mirror of
https://github.com/beetbox/beets.git
synced 2025-12-25 18:13:17 +01:00
Featured artists extracted and appended, need to see if join needs to be variable
This commit is contained in:
parent
84e52e1b4a
commit
2bf411e77d
2 changed files with 23 additions and 10 deletions
|
|
@ -339,7 +339,7 @@ class DiscogsPlugin(MetadataSourcePlugin):
|
|||
# convenient `.tracklist` property, which will strip out useful artist
|
||||
# information and leave us with skeleton `Artist` objects that will
|
||||
# each make an API call just to get the same data back.
|
||||
tracks = self.get_tracks(result.data["tracklist"])
|
||||
tracks = self.get_tracks(result.data["tracklist"], artist, artist_id)
|
||||
|
||||
# Extract information for the optional AlbumInfo fields, if possible.
|
||||
va = result.data["artists"][0].get("name", "").lower() == "various"
|
||||
|
|
@ -446,7 +446,7 @@ class DiscogsPlugin(MetadataSourcePlugin):
|
|||
else:
|
||||
return None
|
||||
|
||||
def get_tracks(self, tracklist):
|
||||
def get_tracks(self, tracklist, album_artist, album_artist_id):
|
||||
"""Returns a list of TrackInfo objects for a discogs tracklist."""
|
||||
try:
|
||||
clean_tracklist = self.coalesce_tracks(tracklist)
|
||||
|
|
@ -471,7 +471,8 @@ class DiscogsPlugin(MetadataSourcePlugin):
|
|||
# divisions.
|
||||
divisions += next_divisions
|
||||
del next_divisions[:]
|
||||
track_info = self.get_track_info(track, index, divisions)
|
||||
track_info = self.get_track_info(track, index, divisions,
|
||||
album_artist, album_artist_id)
|
||||
track_info.track_alt = track["position"]
|
||||
tracks.append(track_info)
|
||||
else:
|
||||
|
|
@ -638,7 +639,7 @@ class DiscogsPlugin(MetadataSourcePlugin):
|
|||
return text
|
||||
return DISAMBIGUATION_RE.sub("", text)
|
||||
|
||||
def get_track_info(self, track, index, divisions):
|
||||
def get_track_info(self, track, index, divisions, album_artist, album_artist_id):
|
||||
"""Returns a TrackInfo object for a discogs track."""
|
||||
title = track["title"]
|
||||
if self.config["index_tracks"]:
|
||||
|
|
@ -650,9 +651,18 @@ class DiscogsPlugin(MetadataSourcePlugin):
|
|||
artist, artist_id = self.get_artist(
|
||||
track.get("artists", []), join_key="join"
|
||||
)
|
||||
# If no artist and artist is returned, set to match album artist
|
||||
if not artist:
|
||||
artist = album_artist
|
||||
artist_id = album_artist_id
|
||||
artist = self.strip_disambiguation(artist)
|
||||
length = self.get_track_length(track["duration"])
|
||||
featured = map(lambda artist: artist["name"] if artist["role"].find("Featuring") else "", track.get("extraartists", []))
|
||||
# Add featured artists
|
||||
extraartists = track.get("extraartists", [])
|
||||
featured = [
|
||||
artist["name"] for artist in extraartists if artist["role"].find("Featuring") != -1]
|
||||
if featured:
|
||||
artist = f"{artist} feat. {', '.join(featured)}"
|
||||
return TrackInfo(
|
||||
title=title,
|
||||
track_id=track_id,
|
||||
|
|
|
|||
|
|
@ -477,16 +477,19 @@ class DGAlbumInfoTest(BeetsTestCase):
|
|||
"role": "Featuring",
|
||||
}]
|
||||
},
|
||||
"ARTIST feat. PERFORMER & MUSICIAN"
|
||||
"ARTIST feat. PERFORMER, MUSICIAN"
|
||||
),
|
||||
({
|
||||
"type_": "track",
|
||||
"title": "track",
|
||||
"position": "1",
|
||||
"duration": "5:00",
|
||||
"artist": "NEW ARTIST",
|
||||
"artists": [{
|
||||
"name": "NEW ARTIST",
|
||||
"tracks": "",
|
||||
"id": 11146}],
|
||||
"extraartists": [{
|
||||
"name": "SOLIST",
|
||||
"name": "SOLOIST",
|
||||
"role": "Featuring",
|
||||
}, {
|
||||
"name": "PERFORMER",
|
||||
|
|
@ -499,14 +502,14 @@ class DGAlbumInfoTest(BeetsTestCase):
|
|||
"role": "Featuring",
|
||||
}]
|
||||
},
|
||||
"NEW ARTIST feat. SOLIST, PERFORMER & MUSICIAN"
|
||||
"NEW ARTIST feat. SOLOIST, PERFORMER, MUSICIAN"
|
||||
)])
|
||||
@patch("beetsplug.discogs.DiscogsPlugin.setup", Mock())
|
||||
def test_parse_featured_artists(track, expected_artist):
|
||||
""" Tests the plugins ability to parse a featured artist.
|
||||
Initial check with one featured artist, two featured artists,
|
||||
and three. Ignores artists that are not listed as featured."""
|
||||
t = DiscogsPlugin().get_track_info(track, 1, 1)
|
||||
t = DiscogsPlugin().get_track_info(track, 1, 1, "ARTIST", 2)
|
||||
assert t.artist == expected_artist
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
|
|||
Loading…
Reference in a new issue