mirror of
https://github.com/beetbox/beets.git
synced 2026-02-08 16:34:12 +01:00
Refactor _get_related_artist_names
This commit is contained in:
parent
1ab72230e0
commit
2b9bad71c5
3 changed files with 38 additions and 28 deletions
|
|
@ -155,16 +155,10 @@ def track_url(trackid: str) -> str:
|
|||
def _get_related_artist_names(
|
||||
relations: list[ArtistRelation], relation_type: ArtistRelationType
|
||||
) -> str:
|
||||
"""Given a list representing the artist relationships extract the names of
|
||||
the remixers and concatenate them.
|
||||
"""
|
||||
related_artists = []
|
||||
|
||||
for relation in relations:
|
||||
if relation["type"] == relation_type:
|
||||
related_artists.append(relation["artist"]["name"])
|
||||
|
||||
return ", ".join(related_artists)
|
||||
"""Return a comma-separated list of artist names for a relation type."""
|
||||
return ", ".join(
|
||||
r["artist"]["name"] for r in relations if r["type"] == relation_type
|
||||
)
|
||||
|
||||
|
||||
def album_url(albumid: str) -> str:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
import factory
|
||||
from factory.fuzzy import FuzzyChoice
|
||||
|
||||
from beetsplug._utils.musicbrainz import ArtistRelationType
|
||||
|
||||
|
||||
class _SortNameFactory(factory.DictFactory):
|
||||
|
|
@ -6,13 +9,16 @@ class _SortNameFactory(factory.DictFactory):
|
|||
sort_name = factory.LazyAttribute(lambda o: f"{o.name}, The")
|
||||
|
||||
|
||||
class AliasFactory(_SortNameFactory):
|
||||
class Params:
|
||||
suffix = ""
|
||||
|
||||
class _PeriodFactory(factory.DictFactory):
|
||||
begin: str | None = None
|
||||
end: str | None = None
|
||||
ended = factory.LazyAttribute(lambda obj: obj.end is not None)
|
||||
|
||||
|
||||
class AliasFactory(_SortNameFactory, _PeriodFactory):
|
||||
class Params:
|
||||
suffix = ""
|
||||
|
||||
locale: str | None = None
|
||||
name = factory.LazyAttribute(lambda o: f"Alias {o.suffix}")
|
||||
primary = False
|
||||
|
|
@ -39,3 +45,20 @@ class ArtistCreditFactory(factory.DictFactory):
|
|||
artist = factory.SubFactory(ArtistFactory)
|
||||
joinphrase = ""
|
||||
name = factory.LazyAttribute(lambda o: f"{o.artist['name']} Credit")
|
||||
|
||||
|
||||
class ArtistRelationFactory(_PeriodFactory):
|
||||
artist = factory.SubFactory(
|
||||
ArtistFactory,
|
||||
name=factory.LazyAttribute(
|
||||
lambda o: f"{o.factory_parent.type.capitalize()} Artist"
|
||||
),
|
||||
)
|
||||
attribute_ids = factory.Dict({})
|
||||
attribute_credits = factory.Dict({})
|
||||
attributes = factory.List([])
|
||||
direction = "backward"
|
||||
source_credit = ""
|
||||
target_credit = ""
|
||||
type = FuzzyChoice(ArtistRelationType.__args__) # type: ignore[attr-defined]
|
||||
type_id = factory.Faker("uuid4")
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ def artist_credit_factory(**kwargs) -> mb.ArtistCredit:
|
|||
return factories.ArtistCreditFactory.build(**kwargs)
|
||||
|
||||
|
||||
def artist_relation_factory(**kwargs) -> mb.ArtistRelation:
|
||||
return factories.ArtistRelationFactory.build(**kwargs)
|
||||
|
||||
|
||||
class MusicBrainzTestCase(BeetsTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
|
@ -187,20 +191,9 @@ class MusicBrainzTestCase(BeetsTestCase):
|
|||
)
|
||||
if remixer:
|
||||
recording["artist_relations"] = [
|
||||
{
|
||||
"type": "remixer",
|
||||
"type_id": "RELATION TYPE ID",
|
||||
"direction": "backward",
|
||||
"artist": artist_factory(name="Recording Remixer"),
|
||||
"attribute_ids": {},
|
||||
"attribute_values": {},
|
||||
"attributes": [],
|
||||
"begin": None,
|
||||
"end": None,
|
||||
"ended": False,
|
||||
"source_credit": "",
|
||||
"target_credit": "",
|
||||
}
|
||||
artist_relation_factory(
|
||||
type="remixer", artist__name="Recording Remixer"
|
||||
)
|
||||
]
|
||||
return recording
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue