Backfill album release_date from stream tags when T2Tunes metadata omits it

T2Tunes albumList entries may not include a release_date field, leaving the
$year path template empty. get_album() now falls back to the first track's
release_date (populated from the FLAC date tag via get_album_tracks) when
album metadata has none. Also try camelCase releaseDate key at all albumList
read sites (Album.from_metadata, get_album, _fetch_album_metas consumers).

1 new test: release_date backfilled from stream date tag when absent from
album metadata. date tag "2024-11-22" added to MEDIA_RESPONSE_FLAC fixture.
pull/617/head
Broque Thomas 1 week ago
parent 96a1c8b7b8
commit d944884ab4

@ -486,12 +486,18 @@ class AmazonClient:
"label": album.get("label", ""),
}
if include_tracks:
result["tracks"] = self.get_album_tracks(asin) or {
"items": [],
"total": 0,
"limit": 50,
"next": None,
tracks_data = self.get_album_tracks(asin) or {
"items": [], "total": 0, "limit": 50, "next": None,
}
result["tracks"] = tracks_data
# Backfill release_date from stream tags when album metadata lacks it.
if not result["release_date"]:
items = tracks_data.get("items") or []
for item in items:
rd = item.get("release_date") or ""
if rd and len(rd) >= 4:
result["release_date"] = rd
break
return result
def get_album_tracks(self, asin: str) -> Optional[Dict[str, Any]]:

@ -126,6 +126,7 @@ MEDIA_RESPONSE_FLAC = {
"isrc": "USRC12345678",
"trackNumber": "3",
"discNumber": "1",
"date": "2024-11-22",
},
}
@ -810,6 +811,13 @@ class TestGetAlbum:
album = client.get_album("B0ABCDE123", include_tracks=False)
assert "tracks" not in album
def test_release_date_backfilled_from_stream_tags(self):
# ALBUM_METADATA_RESPONSE has no release_date — should fall back to track date tag
client = self._client()
with patch("core.amazon_client._rate_limit"):
album = client.get_album("B0ABCDE123")
assert album["release_date"] == "2024-11-22"
def test_returns_none_on_empty_albumlist(self):
client = _make_client({"amazon-music/metadata": {"albumList": []}})
with patch("core.amazon_client._rate_limit"):

Loading…
Cancel
Save