track_delta
¶
Utilities for incremental track synchronization using CSV deltas.
TrackDelta
dataclass
¶
split_applescript_rows
¶
Split raw AppleScript output into individual track rows.
Python's str.splitlines() treats \x1e (our field separator) as a
line boundary, breaking single-track responses into per-field rows. This
helper centralises the split-vs-splitlines decision so both parsers
(parse_tracks and parse_osascript_output) stay in sync.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
str
|
Stripped raw AppleScript output. |
required |
field_separator
|
str
|
Detected field separator (FIELD_SEPARATOR or |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of raw track row strings. |
Source code in src/core/tracks/track_delta.py
has_track_changed
¶
Check if track metadata has changed between current and stored versions.
Only checks fields relevant to genre/year processing. Excludes last_modified and date_added because they change for many reasons unrelated to our updates (e.g., playback, ratings, other metadata edits) and cause false positives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current
|
TrackDict
|
Current track from Apple Music |
required |
stored
|
TrackDict
|
Stored track from CSV snapshot |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if any relevant field has changed (track_status, genre, year) |
Source code in src/core/tracks/track_delta.py
has_identity_changed
¶
Check if track identity (artist or album) has changed.
When artist or album changes, the API cache for the OLD artist/album becomes stale and must be invalidated. This is separate from has_track_changed() which only checks fields we manage (genre, year).
Used for headless daemon mode to automatically detect user edits in Music.app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current
|
TrackDict
|
Current track from Apple Music |
required |
stored
|
TrackDict
|
Stored track from snapshot |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if artist or album changed (requires cache invalidation for old values) |
Source code in src/core/tracks/track_delta.py
compute_track_delta
¶
Compute track delta given current TrackDict objects and CSV snapshot.