Skip to content

Commit 16b2a4f

Browse files
OzGavCopilot
andauthored
Fix ISRC lookups failing for Last.fm track MBIDs (#4185)
# What does this implement/fix? <!-- Quick description and explanation of changes. --> Last.fm often supplies a track MBID where a recording MBID is expected, so the direct recording lookup returned 404 and most tracks resolved without ISRCs even though they exist in MusicBrainz. Resolve the ID via a single search on both ID kinds instead (the search response includes the ISRCs), keep the direct lookup as fallback for merged recording MBIDs, and cache the result for 30 days. **Related issue (if applicable):** - related issue <link to issue> ## Types of changes <!-- Tick exactly one box. CI (.github/workflows/pr-labels.yaml) derives the label from the ticked box and applies it automatically; the release-notes generator uses that same label to slot this change into the next release notes. --> - [X] Bugfix (non-breaking change which fixes an issue) — `bugfix` - [ ] New feature (non-breaking change which adds functionality) — `new-feature` - [ ] Enhancement to an existing feature — `enhancement` - [ ] New music/player/metadata/plugin provider — `new-provider` - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) — `breaking-change` - [ ] Refactor (no behaviour change) — `refactor` - [ ] Documentation only — `documentation` - [ ] Maintenance / chore — `maintenance` - [ ] CI / workflow change — `ci` - [ ] Dependencies bump — `dependencies` ## Checklist - [X] The code change is tested and works locally. - [X] `pre-commit run --all-files` passes. - [X] `pytest` passes, and tests have been added/updated under `tests/` where applicable. - [ ] For changes to shared models, the companion PR in `music-assistant/models` is linked. - [ ] For changes affecting the UI, the companion PR in `music-assistant/frontend` is linked. - [X] I have read and complied with the project's [AI Policy](https://github.com/music-assistant/.github/blob/main/AI_POLICY.md) for any AI-assisted contributions. - [ ] I have raised a PR against the documentation repository targeting the main or beta branch as appropriate. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent eb39dea commit 16b2a4f

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

music_assistant/providers/musicbrainz/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,24 @@ async def get_recording_details(self, recording_id: str) -> MusicBrainzRecording
429429
msg = "Invalid MusicBrainz recording ID provided"
430430
raise InvalidDataError(msg)
431431

432+
@use_cache(86400 * 30)
432433
async def get_isrcs_for_recording(self, recording_id: str) -> list[str]:
433434
"""
434435
Get ISRCs for a MusicBrainz Recording ID.
435436
436-
:param recording_id: MusicBrainz recording ID.
437-
:return: List of ISRCs, or empty list if not found or on error.
437+
:param recording_id: MusicBrainz recording ID, or a track ID as
438+
handed out by e.g. Last.fm.
439+
:return: List of ISRCs, or empty list if not found.
438440
"""
441+
# the search response includes the ISRCs, so either ID kind costs one call
442+
safe_id = re.sub(LUCENE_SPECIAL, r"\\\1", recording_id)
443+
query = f"rid:{safe_id} OR tid:{safe_id}"
444+
if (result := await self.get_data("recording", query=query)) and (
445+
recordings := result.get("recordings")
446+
):
447+
return recordings[0].get("isrcs") or []
448+
# merged (redirected) recording MBIDs are absent from the search
449+
# index but still resolve via direct lookup
439450
with suppress(InvalidDataError):
440451
recording = await self.get_recording_details(recording_id)
441452
return recording.isrcs or []

0 commit comments

Comments
 (0)