year_determination
¶
Year determination logic for albums.
This module contains the core logic for determining album years from various sources: local data, cache, and external APIs.
YearDeterminator
¶
YearDeterminator(
*,
cache_service,
external_api,
pending_verification,
consistency_checker,
fallback_handler,
console_logger,
error_logger,
config
)
Determines album year from various sources.
Responsibilities: - Query cache for existing year data - Query external APIs when needed - Apply fallback logic for uncertain updates - Handle prerelease and suspicious albums - Skip albums that already have valid years
Initialize the YearDeterminator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_service
|
CacheServiceProtocol
|
Cache service for storing/retrieving years |
required |
external_api
|
ExternalApiServiceProtocol
|
External API service for fetching years |
required |
pending_verification
|
PendingVerificationServiceProtocol
|
Service for managing pending verifications |
required |
consistency_checker
|
YearConsistencyChecker
|
Checker for year consistency |
required |
fallback_handler
|
YearFallbackHandler
|
Handler for fallback logic |
required |
console_logger
|
Logger
|
Logger for console output |
required |
error_logger
|
Logger
|
Logger for error messages |
required |
config
|
AppConfig
|
Typed application configuration |
required |
Source code in src/core/tracks/year_determination.py
determine_album_year
async
¶
Determine year for album using simplified Linus approach.
Order: dominant year -> cache (high confidence) -> consensus release_year -> API -> None When force=True, skips local sources - always queries API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
album_tracks
|
list[TrackDict]
|
List of tracks in the album |
required |
force
|
bool
|
If True, bypass local data and always query API |
False
|
Returns:
| Type | Description |
|---|---|
str | None
|
Year string if found, None otherwise |
Source code in src/core/tracks/year_determination.py
should_skip_album
async
¶
Check pre-conditions BEFORE any API call.
Guard clauses prevent wasted API calls by checking inexpensive conditions first. Trusts cache (API data) over Music.app data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
album_tracks
|
list[TrackDict]
|
List of tracks in the album |
required |
artist
|
str
|
Artist name for logging |
required |
album
|
str
|
Album name for logging |
required |
force
|
bool
|
If True, never skip - always process the album |
False
|
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Tuple of (should_skip, reason) where reason is empty if not skipping. |
Source code in src/core/tracks/year_determination.py
check_prerelease_status
async
¶
Check if the album should be skipped due to prerelease status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
album_tracks
|
list[TrackDict]
|
List of tracks on the album |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the album should be skipped, False otherwise |
Source code in src/core/tracks/year_determination.py
check_suspicious_album
async
¶
Check if the album is suspicious and should be skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
album_tracks
|
list[TrackDict]
|
List of tracks |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if album should be skipped, False otherwise |
Source code in src/core/tracks/year_determination.py
handle_future_years
async
¶
Handle case when future years are found in tracks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
album_tracks
|
list[TrackDict]
|
Album tracks |
required |
future_years
|
list[int]
|
List of future years found |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if album should be skipped |
Source code in src/core/tracks/year_determination.py
extract_future_years
staticmethod
¶
Extract future years from album tracks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
album_tracks
|
list[TrackDict]
|
List of tracks from the album |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
List of years that are in the future |
Source code in src/core/tracks/year_determination.py
extract_release_years
staticmethod
¶
Extract valid release years from album tracks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
album_tracks
|
list[TrackDict]
|
List of tracks from the album |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of valid release years from track metadata |