Remove _artist_ids

This commit is contained in:
Šarūnas Nejus 2026-01-22 01:37:03 +00:00
parent 70df5de2a7
commit 0dcb216d4f
No known key found for this signature in database
2 changed files with 16 additions and 23 deletions

View file

@ -109,9 +109,11 @@ UrlSource = Literal[
class ArtistInfo(TypedDict):
artist: str
artist_id: str
artist_sort: str
artist_credit: str
artists: list[str]
artists_ids: list[str]
artists_sort: list[str]
artists_credit: list[str]
@ -150,19 +152,6 @@ def track_url(trackid: str) -> str:
return urljoin(BASE_URL, f"recording/{trackid}")
def _artist_ids(credit: list[ArtistCredit]) -> list[str]:
"""
Given a list representing an ``artist-credit``,
return a list of artist IDs
"""
artist_ids: list[str] = []
for el in credit:
if isinstance(el, dict):
artist_ids.append(el["artist"]["id"])
return artist_ids
def _get_related_artist_names(
relations: list[ArtistRelation], relation_type: ArtistRelationType
) -> str:
@ -330,8 +319,10 @@ class MusicBrainzPlugin(MusicBrainzAPIMixin, MetadataSourcePlugin):
artists: list[str] = []
artists_sort: list[str] = []
artists_credit: list[str] = []
artists_ids: list[str] = []
for el in artist_credits:
artists_ids.append(el["artist"]["id"])
alias = _preferred_alias(el["artist"].get("aliases", []))
artist_object = alias or el["artist"]
@ -346,9 +337,11 @@ class MusicBrainzPlugin(MusicBrainzAPIMixin, MetadataSourcePlugin):
return {
"artist": "".join(artist_parts),
"artist_id": artists_ids[0],
"artist_sort": "".join(artist_sort_parts),
"artist_credit": "".join(artist_credit_parts),
"artists": artists,
"artists_ids": artists_ids,
"artists_sort": artists_sort,
"artists_credit": artists_credit,
}
@ -391,9 +384,6 @@ class MusicBrainzPlugin(MusicBrainzAPIMixin, MetadataSourcePlugin):
**self._parse_artist_credits(recording["artist_credit"]),
)
info.artists_ids = _artist_ids(recording["artist_credit"])
info.artist_id = info.artists_ids[0]
if artist_relations := recording.get("artist_relations"):
if remixer := _get_related_artist_names(
artist_relations, "remixer"
@ -510,21 +500,15 @@ class MusicBrainzPlugin(MusicBrainzAPIMixin, MetadataSourcePlugin):
ti.update(
**self._parse_artist_credits(track["artist_credit"])
)
ti.artists_ids = _artist_ids(track["artist_credit"])
ti.artist_id = ti.artists_ids[0]
if track.get("length"):
ti.length = int(track["length"]) / (1000.0)
track_infos.append(ti)
album_artist_ids = _artist_ids(release["artist_credit"])
info = beets.autotag.hooks.AlbumInfo(
**self._parse_artist_credits(release["artist_credit"]),
album=release["title"],
album_id=release["id"],
artist_id=album_artist_ids[0],
artists_ids=album_artist_ids,
tracks=track_infos,
mediums=len(release["media"]),
data_source=self.data_source,

View file

@ -712,9 +712,11 @@ class ArtistTest(unittest.TestCase):
assert MusicBrainzPlugin._parse_artist_credits(credit) == {
"artist": "Artist",
"artist_id": "00000000-0000-0000-0000-000000000001",
"artist_sort": "Artist, The",
"artist_credit": "Artist Credit",
"artists": ["Artist"],
"artists_ids": ["00000000-0000-0000-0000-000000000001"],
"artists_sort": ["Artist, The"],
"artists_credit": ["Artist Credit"],
}
@ -722,14 +724,21 @@ class ArtistTest(unittest.TestCase):
def test_two_artists(self):
credit = [
artist_credit_factory(artist__name="Artist", joinphrase=" AND "),
artist_credit_factory(artist__name="Other Artist"),
artist_credit_factory(
artist__name="Other Artist", artist__id_suffix="1"
),
]
assert MusicBrainzPlugin._parse_artist_credits(credit) == {
"artist": "Artist AND Other Artist",
"artist_id": "00000000-0000-0000-0000-000000000001",
"artist_sort": "Artist, The AND Other Artist, The",
"artist_credit": "Artist Credit AND Other Artist Credit",
"artists": ["Artist", "Other Artist"],
"artists_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002",
],
"artists_sort": ["Artist, The", "Other Artist, The"],
"artists_credit": ["Artist Credit", "Other Artist Credit"],
}