fix(worker): prefer the original release-group over same-titled reissues
The real root cause of "Hybrid Theory" re-downloading forever: MB lists the 2000 original and a 2023 reissue as SEPARATE same-titled Album release-groups. They tie on (artist, title, is_album), so _best_release_group kept whichever MB relevance-ordered first — the 2023 reissue (13 tracks / ~52 min). Its inflated tracklist+runtime then failed the completeness/duration checks against the standard 12-track album sources deliver, looping endlessly. Add an earliest-first-release-date tie-break so the original group wins. (Complements _pick_release, which handles reissue releases *within* a group.) 335 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,12 @@ def _is_album(g: dict) -> bool:
|
|||||||
return (g.get("primary-type") or "").casefold() == "album"
|
return (g.get("primary-type") or "").casefold() == "album"
|
||||||
|
|
||||||
|
|
||||||
|
def _rg_year(g: dict) -> int:
|
||||||
|
"""First-release year of a release-group, or 9999 when unknown (so undated groups lose ties)."""
|
||||||
|
frd = (g.get("first-release-date") or "")[:4]
|
||||||
|
return int(frd) if frd.isdigit() else 9999
|
||||||
|
|
||||||
|
|
||||||
def _credited_artist(g: dict) -> str:
|
def _credited_artist(g: dict) -> str:
|
||||||
"""Primary credited artist name of a release-group search result, or '' if absent."""
|
"""Primary credited artist name of a release-group search result, or '' if absent."""
|
||||||
credit = g.get("artist-credit")
|
credit = g.get("artist-credit")
|
||||||
@@ -56,7 +62,12 @@ def _best_release_group(artist: str, album: str, groups: list) -> dict | None:
|
|||||||
* title similarity is next;
|
* title similarity is next;
|
||||||
* an Album primary-type only breaks ties *within* the same artist+title, so a famous
|
* an Album primary-type only breaks ties *within* the same artist+title, so a famous
|
||||||
album (Michael Jackson's "Off the Wall") still isn't resolved to its same-named
|
album (Michael Jackson's "Off the Wall") still isn't resolved to its same-named
|
||||||
single whose short tracklist would map positionally onto the album's files.
|
single whose short tracklist would map positionally onto the album's files;
|
||||||
|
* finally, the EARLIEST release-group wins — MusicBrainz lists the original album and its
|
||||||
|
later reissues/anniversary editions as separate same-titled groups (Linkin Park "Hybrid
|
||||||
|
Theory": a 2000 original and a 2023 13-track reissue), which tie on everything above, so
|
||||||
|
MB's arbitrary relevance order used to pick a reissue whose longer tracklist/runtime then
|
||||||
|
failed completeness checks against the standard album a source delivers. Prefer the original.
|
||||||
Artist is a ranking signal, never a hard filter — a low match sinks a candidate but
|
Artist is a ranking signal, never a hard filter — a low match sinks a candidate but
|
||||||
never drops the release, so credited-name variations (feat., punctuation) still resolve.
|
never drops the release, so credited-name variations (feat., punctuation) still resolve.
|
||||||
Returns None below the title threshold. Pure — no network I/O."""
|
Returns None below the title threshold. Pure — no network I/O."""
|
||||||
@@ -68,6 +79,7 @@ def _best_release_group(artist: str, album: str, groups: list) -> dict | None:
|
|||||||
_ratio(artist, _credited_artist(g)),
|
_ratio(artist, _credited_artist(g)),
|
||||||
_ratio(album, g.get("title", "")),
|
_ratio(album, g.get("title", "")),
|
||||||
_is_album(g),
|
_is_album(g),
|
||||||
|
-_rg_year(g), # tie-break: the original (earliest) group over later reissues
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if _ratio(album, best.get("title", "")) < _MIN_TITLE_RATIO:
|
if _ratio(album, best.get("title", "")) < _MIN_TITLE_RATIO:
|
||||||
|
|||||||
@@ -51,6 +51,21 @@ def test_empty_groups_returns_none():
|
|||||||
assert _best_release_group("Michael Jackson", "Off the Wall", []) is None
|
assert _best_release_group("Michael Jackson", "Off the Wall", []) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_prefers_original_group_over_later_reissue():
|
||||||
|
# Real "Hybrid Theory" bug: MB lists a 2000 original and a 2023 reissue as separate same-titled
|
||||||
|
# Album groups (tie on artist/title/type). The reissue's longer tracklist fails completeness
|
||||||
|
# checks, so the original (earliest) must win regardless of MB's relevance order.
|
||||||
|
groups = [
|
||||||
|
{"id": "reissue", "title": "Hybrid Theory", "primary-type": "Album",
|
||||||
|
"first-release-date": "2023-07-21",
|
||||||
|
"artist-credit": [{"artist": {"name": "Linkin Park"}}]},
|
||||||
|
{"id": "original", "title": "Hybrid Theory", "primary-type": "Album",
|
||||||
|
"first-release-date": "2000-10-24",
|
||||||
|
"artist-credit": [{"artist": {"name": "Linkin Park"}}]},
|
||||||
|
]
|
||||||
|
assert _best_release_group("Linkin Park", "Hybrid Theory", groups)["id"] == "original"
|
||||||
|
|
||||||
|
|
||||||
def test_prefers_credited_artist_over_same_titled_other_artist_album():
|
def test_prefers_credited_artist_over_same_titled_other_artist_album():
|
||||||
# Real-world "Fun Machine" bug: Lake Street Dive's EP is what we followed, but two
|
# Real-world "Fun Machine" bug: Lake Street Dive's EP is what we followed, but two
|
||||||
# unrelated bands also have a release group literally titled "Fun Machine" as an Album.
|
# unrelated bands also have a release group literally titled "Fun Machine" as an Album.
|
||||||
|
|||||||
Reference in New Issue
Block a user