track_processor
¶
Track processing functionality for Music Genre Updater.
This module handles fetching tracks from Music.app, caching, and updating track properties.
TrackProcessor
¶
TrackProcessor(
ap_client,
cache_service,
*,
library_snapshot_service=None,
console_logger,
error_logger,
config,
analytics,
dry_run=False,
security_validator=None
)
Handles track fetching and updating operations.
Initialize the TrackProcessor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ap_client
|
AppleScriptClientProtocol
|
AppleScript client for Music.app communication |
required |
cache_service
|
CacheServiceProtocol
|
Cache service for storing track data |
required |
library_snapshot_service
|
LibrarySnapshotServiceProtocol | None
|
Optional library snapshot service for cached snapshots |
None
|
console_logger
|
Logger
|
Logger for console output |
required |
error_logger
|
Logger
|
Logger for error messages |
required |
config
|
AppConfig
|
Typed application configuration |
required |
analytics
|
AnalyticsProtocol
|
Service for tracking method calls |
required |
dry_run
|
bool
|
Whether to run in dry-run mode |
False
|
security_validator
|
SecurityValidator | None
|
Optional security validator for input sanitization |
None
|
Source code in src/core/tracks/track_processor.py
set_dry_run_context
¶
Set dry run context for test mode filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
Dry run mode ('test' or other) |
required |
test_artists
|
set[str]
|
Set of test artists for filtering |
required |
Source code in src/core/tracks/track_processor.py
set_artist_renamer
¶
fetch_tracks_by_ids
async
¶
Fetch detailed track metadata for the provided track IDs.
Source code in src/core/tracks/track_processor.py
fetch_tracks_async
async
¶
fetch_tracks_async(
artist=None,
force_refresh=False,
dry_run_test_tracks=None,
ignore_test_filter=False,
)
Fetch tracks from cache or Music.app with caching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str | None
|
Optional artist filter |
None
|
force_refresh
|
bool
|
Force refresh from Music.app |
False
|
dry_run_test_tracks
|
list[TrackDict] | None
|
Test tracks for dry-run mode |
None
|
ignore_test_filter
|
bool
|
Whether to ignore test_artists configuration |
False
|
Returns:
| Type | Description |
|---|---|
list[TrackDict]
|
List of track dictionaries |
Source code in src/core/tracks/track_processor.py
fetch_tracks_in_batches
async
¶
Fetch all tracks from Music.app in batches to avoid timeout.
Delegates to BatchTrackFetcher for batch-based fetching with snapshot support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of tracks to fetch per batch |
500
|
skip_snapshot_check
|
bool
|
Skip snapshot validation (used when already validated upstream) |
False
|
Returns:
| Type | Description |
|---|---|
list[TrackDict]
|
List of all track dictionaries |
Source code in src/core/tracks/track_processor.py
update_track_async
async
¶
update_track_async(
track_id,
new_track_name=None,
new_album_name=None,
new_genre=None,
new_year=None,
track_status=None,
original_artist=None,
original_album=None,
original_track=None,
)
Update multiple properties of a track.
Delegates to TrackUpdateExecutor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track_id
|
str
|
ID of the track to update |
required |
new_track_name
|
str | None
|
New track name (optional) |
None
|
new_album_name
|
str | None
|
New album name (optional) |
None
|
new_genre
|
str | None
|
New genre (optional) |
None
|
new_year
|
str | None
|
New year (optional) |
None
|
track_status
|
str | None
|
Track status to check for prerelease (optional) |
None
|
original_artist
|
str | None
|
Original artist name for contextual logging (optional) |
None
|
original_album
|
str | None
|
Original album name for contextual logging (optional) |
None
|
original_track
|
str | None
|
Original track name for contextual logging (optional) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if all updates are successful, False if any failed |
Source code in src/core/tracks/track_processor.py
update_artist_async
async
¶
Update the artist name for a track.
Delegates to TrackUpdateExecutor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
TrackDict
|
Track dictionary representing the target track |
required |
new_artist_name
|
str
|
Artist name to apply |
required |
original_artist
|
str | None
|
Original artist for logging context (optional) |
None
|
update_album_artist
|
bool
|
If True, also update album_artist field |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if update succeeded, False otherwise |
Source code in src/core/tracks/track_processor.py
get_dry_run_actions
¶
Get the list of dry-run actions recorded.
Delegates to TrackUpdateExecutor.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dry-run action dictionaries |