year_retriever
¶
Year retrieval functionality for Music Genre Updater.
This module provides a facade for album year retrieval and updates. The actual logic is delegated to specialized components: - YearDeterminator: Core year determination logic - YearBatchProcessor: Batch processing with concurrency control - YearConsistencyChecker: Year consistency analysis - YearFallbackHandler: Fallback logic for uncertain updates
YearRetriever
¶
YearRetriever(
*,
track_processor,
cache_service,
external_api,
pending_verification,
retry_handler,
console_logger,
error_logger,
analytics,
config,
dry_run=False
)
Facade for album year retrieval and updates.
This class coordinates the year retrieval subsystem, delegating actual work to specialized components while maintaining backward compatibility with existing code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track_processor
|
TrackProcessor
|
Track processor for updating tracks |
required |
cache_service
|
CacheServiceProtocol
|
Cache service for storing years |
required |
external_api
|
ExternalApiServiceProtocol
|
External API service for fetching years |
required |
pending_verification
|
PendingVerificationServiceProtocol
|
Service for managing pending verifications |
required |
retry_handler
|
DatabaseRetryHandler
|
Retry handler for transient error recovery |
required |
console_logger
|
Logger
|
Logger for console output |
required |
error_logger
|
Logger
|
Logger for error messages |
required |
analytics
|
AnalyticsProtocol
|
Service for performance tracking |
required |
config
|
AppConfig
|
Typed application configuration |
required |
dry_run
|
bool
|
Whether to run in dry-run mode |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
MIN_VALID_YEAR |
Minimum year considered valid |
|
PARITY_THRESHOLD |
Max difference for parity detection |
|
TOP_YEARS_COUNT |
Number of top years to consider for parity |
|
DOMINANCE_MIN_SHARE |
Min share of tracks for dominance (0.0-1.0) |
|
SUSPICIOUS_ALBUM_MIN_LEN |
Album names with length <= this are suspicious |
|
SUSPICIOUS_MANY_YEARS |
If >= this many unique years present, skip auto updates |
|
MAX_RETRY_DELAY_SECONDS |
Maximum delay in seconds between retry attempts |
|
DEFAULT_YEAR_DIFFERENCE_THRESHOLD |
Max allowed year difference before dramatic change |
|
DEFAULT_FALLBACK_ENABLED |
Whether fallback logic is enabled by default |
|
DEFAULT_ABSURD_YEAR_THRESHOLD |
Years below this are considered absurd |
|
DEFAULT_SUSPICION_THRESHOLD_YEARS |
If dominant year is this many years older than earliest track added date, trigger API verification |
|
normalize_collaboration_artist |
Static helper that normalizes collaboration artist names to the main artist for grouping |
Source code in src/core/tracks/year_retriever.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
process_album_years
async
¶
Process and update album years for given tracks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
Tracks to process |
required |
force
|
bool
|
Force update even if year exists (bypasses cache/skip checks) |
False
|
fresh
|
bool
|
Fresh mode - invalidate cache before processing, implies force |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise |
Source code in src/core/tracks/year_retriever.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
get_album_years_with_logs
async
¶
Get album year updates with change logs.
This is the public API for pipeline integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
Tracks to process |
required |
force
|
bool
|
If True, bypass skip checks and re-query API for all albums |
False
|
Returns:
| Type | Description |
|---|---|
tuple[list[TrackDict], list[ChangeLogEntry]]
|
Tuple of (updated_tracks, change_logs) |
Source code in src/core/tracks/year_retriever.py
update_years_from_discogs
async
¶
Update years specifically from Discogs API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
Tracks to process |
required |
force
|
bool
|
If True, bypass skip checks and re-query API for all albums |
False
|
Returns:
| Type | Description |
|---|---|
tuple[list[TrackDict], list[ChangeLogEntry]]
|
Tuple of (updated_tracks, change_logs) |
Source code in src/core/tracks/year_retriever.py
get_dry_run_actions
¶
get_last_updated_tracks
¶
set_last_updated_tracks
¶
Set the list of last updated tracks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
List of updated tracks |
required |
update_album_tracks_bulk_async
async
¶
Update year for multiple tracks. Delegates to YearBatchProcessor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
List of tracks to update. |
required |
year
|
str
|
Year value to set. |
required |
artist
|
str
|
Artist name for contextual logging. |
required |
album
|
str
|
Album name for contextual logging. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of (successful_count, failed_count). |