Updates to documentation

This commit is contained in:
Henry 2025-09-26 21:37:18 -07:00
parent 0ec6689395
commit 1e677d57c1
3 changed files with 145 additions and 85 deletions

View file

@ -312,9 +312,10 @@ class DiscogsPlugin(MetadataSourcePlugin):
Calls the parent class get_artist method.""" Calls the parent class get_artist method."""
artist_data = [] artist_data = []
for artist in artists: for artist in artists:
if use_anv and (anv := artist.get("anv", "")): a = artist.copy()
artist["name"] = anv if use_anv and (anv := a.get("anv", "")):
artist_data.append(artist) a["name"] = anv
artist_data.append(a)
artist, artist_id = super().get_artist( artist, artist_id = super().get_artist(
artist_data, join_key="join") artist_data, join_key="join")
return self.strip_disambiguation(artist), artist_id return self.strip_disambiguation(artist), artist_id
@ -659,7 +660,8 @@ class DiscogsPlugin(MetadataSourcePlugin):
self, track, index, divisions, album_artist_data self, track, index, divisions, album_artist_data
): ):
"""Returns a TrackInfo object for a discogs track.""" """Returns a TrackInfo object for a discogs track."""
album_artist, album_artist_id, artist_credit = album_artist_data
artist, artist_id, artist_credit = album_artist_data
title = track["title"] title = track["title"]
if self.config["index_tracks"]: if self.config["index_tracks"]:
@ -669,18 +671,10 @@ class DiscogsPlugin(MetadataSourcePlugin):
track_id = None track_id = None
medium, medium_index, _ = self.get_track_index(track["position"]) medium, medium_index, _ = self.get_track_index(track["position"])
artist = album_artist
artist_credit = artist_credit
artist_id = album_artist_id
# If artists are found on the track, we will use those instead # If artists are found on the track, we will use those instead
if (artists := track.get("artists", [])): if (artists := track.get("artists", [])):
artist, artist_id = self.get_artist(artists, artist, artist_id = self.get_artist(artists, self.config["track_artist_anv"])
self.config["track_artist_anv"] artist_credit, _ = self.get_artist(artists, self.config["artist_credit_anv"])
)
artist_credit, _ = self.get_artist(artists,
self.config["artist_credit_anv"]
)
length = self.get_track_length(track["duration"]) length = self.get_track_length(track["duration"])
# Add featured artists # Add featured artists
@ -690,10 +684,8 @@ class DiscogsPlugin(MetadataSourcePlugin):
in extraartists in extraartists
if "Featuring" if "Featuring"
in artist["role"]] in artist["role"]]
featured, _ = self.get_artist(featured_list, featured, _ = self.get_artist(featured_list, self.config["track_artist_anv"])
self.config["track_artist_anv"]) featured_credit, _ = self.get_artist(featured_list, self.config["artist_credit_anv"])
featured_credit, _ = self.get_artist(featured_list,
self.config["artist_credit_anv"])
if featured: if featured:
artist = f"{artist} {self.config['featured_label']} {featured}" artist = f"{artist} {self.config['featured_label']} {featured}"
artist_credit = f"{artist_credit} {self.config['featured_label']} {featured_credit}" artist_credit = f"{artist_credit} {self.config['featured_label']} {featured_credit}"

View file

@ -16,6 +16,15 @@ New features:
- :doc:`plugins/discogs`: New config option `strip_disambiguation` to toggle - :doc:`plugins/discogs`: New config option `strip_disambiguation` to toggle
stripping discogs numeric disambiguation on artist and label fields. stripping discogs numeric disambiguation on artist and label fields.
- :doc:`plugins/discogs` Added support for featured artists. - :doc:`plugins/discogs` Added support for featured artists.
- :doc:`plugins/discogs` New configuration option `featured_label` to change the
default string used to join featured artists. The default string is `Feat.`
- :doc:`plugins/discogs` Added support for `artist_credit` in Discogs tags
- :doc:`plugins/discogs` Added support for Discogs artist name variations.
Three new boolean configuration options specify where the variations are written,
if at all. `album_artist_anv` writes variations to the album artist tag.
`track_artist_anv` writes to a tracks artist field. `artist_credit_anv` writes
to the `artist_credit` field on both albums and tracks.
Bug fixes: Bug fixes:

View file

@ -452,73 +452,132 @@ class DGAlbumInfoTest(BeetsTestCase):
assert d.label == "LABEL NAME (5)" assert d.label == "LABEL NAME (5)"
config["discogs"]["strip_disambiguation"] = True config["discogs"]["strip_disambiguation"] = True
def test_use_anv(self):
""" Test using artist name variations. """
test_cases = [ @pytest.mark.parametrize(
({ "config_input,expected_output",
"track_artist_anv": False, [
"album_artist_anv": False, ({
"artist_credit_anv": False "track_artist_anv": False,
}, "album_artist_anv": False,
{ "artist_credit_anv": False
"album_artist": "ARTIST NAME & SOLOIST", },
"album_artist_credit": "ARTIST NAME & SOLOIST", {
"track_artist": "ARTIST Feat. PERFORMER", "track_artist": "ARTIST Feat. PERFORMER",
"track_artist_credit": "ARTIST Feat. PERFORMER" "track_artist_credit": "ARTIST Feat. PERFORMER",
}), "album_artist": "ARTIST & SOLOIST",
({ "album_artist_credit": "ARTIST & SOLOIST",
"track_artist_anv": True, }),
"album_artist_anv": False, ({
"artist_credit_anv": False "track_artist_anv": True,
}, "album_artist_anv": False,
{ "artist_credit_anv": False
"album_artist": "ARTIST NAME & SOLOIST", },
"album_artist_credit": "ARTIST NAME & SOLOIST", {
"track_artist": "ARTY Feat. FORMER", "track_artist": "VARIATION Feat. VARIATION",
"track_artist_credit": "ARTIST Feat. PERFORMER" "track_artist_credit": "ARTIST Feat. PERFORMER",
})] "album_artist": "ARTIST & SOLOIST",
data = { "album_artist_credit": "ARTIST & SOLOIST",
"id": 123, }),
"uri": "https://www.discogs.com/release/123456-something", ({
"tracklist": [{ "track_artist_anv": True,
"title": "track", "album_artist_anv": True,
"position": "A", "artist_credit_anv": False
"type_": "track", },
"duration": "5:44", {
"artists": [{ "track_artist": "VARIATION Feat. VARIATION",
"name": "ARTIST", "track_artist_credit": "ARTIST Feat. PERFORMER",
"tracks": "", "album_artist": "VARIATION & VARIATION",
"anv": "ARTY", "album_artist_credit": "ARTIST & SOLOIST",
"id": 11146 }),
}], ({
"extraartists": [{ "track_artist_anv": True,
"name": "PERFORMER", "album_artist_anv": True,
"role": "Featuring", "artist_credit_anv": True
"anv": "FORMER", },
"id": 787 {
}], "track_artist": "VARIATION Feat. VARIATION",
}], "track_artist_credit": "VARIATION Feat. VARIATION",
"artists": [ "album_artist": "VARIATION & VARIATION",
{"name": "ARTIST NAME", "anv": "ARTISTIC", "id": 321, "join": "&"}, "album_artist_credit": "VARIATION & VARIATION",
{"name": "SOLOIST", "anv": "SOLO", "id": 445, "join": ""}, })
], ])
"title": "title", @patch("beetsplug.discogs.DiscogsPlugin.setup", Mock())
} def test_anv(config_input, expected_output):
release = Bag( """ Test using artist name variations. """
data=data, data = {
title=data["title"], "id": 123,
artists=[Bag(data=d) for d in data["artists"]], "uri": "https://www.discogs.com/release/123456-something",
) "tracklist": [{
for test_case in test_cases: "title": "track",
config_input, expected_output = test_case "position": "A",
config["discogs"]["album_artist_anv"] = config_input["album_artist_anv"] "type_": "track",
config["discogs"]["track_artist_anv"] = config_input["track_artist_anv"] "duration": "5:44",
config["discogs"]["artist_credit_anv"] = config_input["artist_credit_anv"] "artists": [{
r = DiscogsPlugin().get_album_info(release) "name": "ARTIST",
assert r.artist == expected_output["album_artist"] "tracks": "",
assert r.artist_credit == expected_output["album_artist_credit"] "anv": "VARIATION",
assert r.tracks[0].artist == expected_output["track_artist"] "id": 11146
assert r.tracks[0].artist_credit == expected_output["track_artist_credit"] }],
"extraartists": [{
"name": "PERFORMER",
"role": "Featuring",
"anv": "VARIATION",
"id": 787
}],
}],
"artists": [
{"name": "ARTIST (4)", "anv": "VARIATION", "id": 321, "join": "&"},
{"name": "SOLOIST", "anv": "VARIATION", "id": 445, "join": ""},
],
"title": "title",
}
release = Bag(
data=data,
title=data["title"],
artists=[Bag(data=d) for d in data["artists"]],
)
config["discogs"]["album_artist_anv"] = config_input["album_artist_anv"]
config["discogs"]["track_artist_anv"] = config_input["track_artist_anv"]
config["discogs"]["artist_credit_anv"] = config_input["artist_credit_anv"]
r = DiscogsPlugin().get_album_info(release)
assert r.artist == expected_output["album_artist"]
assert r.artist_credit == expected_output["album_artist_credit"]
assert r.tracks[0].artist == expected_output["track_artist"]
assert r.tracks[0].artist_credit == expected_output["track_artist_credit"]
@patch("beetsplug.discogs.DiscogsPlugin.setup", Mock())
def test_anv_album_artist():
""" Test using artist name variations when the album artist
is the same as the track artist, but only the track artist
should use the artist name variation."""
data = {
"id": 123,
"uri": "https://www.discogs.com/release/123456-something",
"tracklist": [{
"title": "track",
"position": "A",
"type_": "track",
"duration": "5:44",
}],
"artists": [
{"name": "ARTIST (4)", "anv": "VARIATION", "id": 321},
],
"title": "title",
}
release = Bag(
data=data,
title=data["title"],
artists=[Bag(data=d) for d in data["artists"]],
)
config["discogs"]["album_artist_anv"] = False
config["discogs"]["track_artist_anv"] = True
config["discogs"]["artist_credit_anv"] = False
r = DiscogsPlugin().get_album_info(release)
assert r.artist == "ARTIST"
assert r.artist_credit == "ARTIST"
assert r.tracks[0].artist == "VARIATION"
assert r.tracks[0].artist_credit == "ARTIST"
@pytest.mark.parametrize( @pytest.mark.parametrize(
"track, expected_artist", "track, expected_artist",