diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 5bdd27705..3385e4221 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -425,6 +425,8 @@ class DiscogsPlugin(BeetsPlugin): catalogno = result.data["labels"][0].get("catno") labelid = result.data["labels"][0].get("id") + cover_art_url = self.select_cover_art(result) + # Additional cleanups (various artists name, catalog number, media). if va: artist = config["va_name"].as_str() @@ -474,8 +476,19 @@ class DiscogsPlugin(BeetsPlugin): discogs_albumid=discogs_albumid, discogs_labelid=labelid, discogs_artistid=artist_id, + cover_art_url=cover_art_url, ) + def select_cover_art(self, result): + """Returns the best candidate image, if any, from a Discogs `Release` object.""" + if result.data.get("images") and len(result.data.get("images")) > 0: + # The first image in this list appears to be the one displayed first + # on the release page - even if it is not flagged as `type: "primary"` - and + # so it is the best candidate for the cover art. + return result.data.get("images")[0].get("uri") + + return None + def format(self, classification): if classification: return ( diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index f1b012a5f..93d3f2c57 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -1098,7 +1098,7 @@ class CoverArtUrl(RemoteArtSource): image_url = None try: # look for cover_art_url on album or first track - if album.cover_art_url: + if album.get("cover_art_url"): image_url = album.cover_art_url else: image_url = album.items().get().cover_art_url diff --git a/docs/changelog.rst b/docs/changelog.rst index 13e75a904..a6ae89a7a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,6 +17,8 @@ Major new features: New features: +* :doc:`plugins/discogs`: supply a value for the `cover_art_url` attribute, for use by `fetchart`. + :bug:`429` * :ref:`update-cmd`: added ```-e``` flag for excluding fields from being updated. * :doc:`/plugins/deezer`: Import rank and other attributes from Deezer during import and add a function to update the rank of existing items. :bug:`4841`