From c31146e3f529389259bdc47ab2e37804b83abdaa Mon Sep 17 00:00:00 2001 From: "U-LAPTOP-4EP3DB2K\\alexa" Date: Sun, 22 Oct 2023 20:42:45 +0800 Subject: [PATCH 1/5] Discogs <-> fetchart integration --- beetsplug/discogs.py | 7 +++++-- beetsplug/fetchart.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index d804a3e15..f59869e68 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -399,7 +399,7 @@ class DiscogsPlugin(BeetsPlugin): # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. - albumtype = media = label = catalogno = labelid = None + albumtype = media = label = catalogno = labelid = cover_art_url = None if result.data.get('formats'): albumtype = ', '.join( result.data['formats'][0].get('descriptions', [])) or None @@ -408,6 +408,8 @@ class DiscogsPlugin(BeetsPlugin): label = result.data['labels'][0].get('name') catalogno = result.data['labels'][0].get('catno') labelid = result.data['labels'][0].get('id') + if result.data.get('cover_image'): + cover_art_url = result.data.get('cover_image') # Additional cleanups (various artists name, catalog number, media). if va: @@ -444,7 +446,8 @@ class DiscogsPlugin(BeetsPlugin): media=media, original_year=original_year, data_source='Discogs', data_url=data_url, discogs_albumid=discogs_albumid, - discogs_labelid=labelid, discogs_artistid=artist_id) + discogs_labelid=labelid, discogs_artistid=artist_id, + cover_art_url=cover_art_url) def format(self, classification): if classification: diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 732031227..5f21859ce 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -992,7 +992,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', None): image_url = album.cover_art_url else: image_url = album.items().get().cover_art_url From e9574bdc21e7848e1f05d6e54f311335608372f0 Mon Sep 17 00:00:00 2001 From: "U-LAPTOP-4EP3DB2K\\alexa" Date: Sun, 22 Oct 2023 20:55:38 +0800 Subject: [PATCH 2/5] Add documentation --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 13e75a904..1cdef2575 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` From 3e06ca2af467170a3a890ac6b58a68aed44925e3 Mon Sep 17 00:00:00 2001 From: "U-LAPTOP-4EP3DB2K\\alexa" Date: Sun, 22 Oct 2023 21:47:46 +0800 Subject: [PATCH 3/5] Use images attr over cover_image --- beetsplug/discogs.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 4628e666d..2063f188c 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -413,7 +413,7 @@ class DiscogsPlugin(BeetsPlugin): # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. - albumtype = media = label = catalogno = labelid = cover_art_url = None + albumtype = media = label = catalogno = labelid = None if result.data.get("formats"): albumtype = ( ", ".join(result.data["formats"][0].get("descriptions", [])) @@ -424,8 +424,8 @@ class DiscogsPlugin(BeetsPlugin): label = result.data["labels"][0].get("name") catalogno = result.data["labels"][0].get("catno") labelid = result.data["labels"][0].get("id") - if result.data.get("cover_image"): - cover_art_url = result.data.get("cover_image") + + cover_art_url = self.select_cover_art(result) # Additional cleanups (various artists name, catalog number, media). if va: @@ -478,6 +478,16 @@ class DiscogsPlugin(BeetsPlugin): 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: From 5fe19c1d1d7cab62bfc9b5cd7b85d6e9d827c62f Mon Sep 17 00:00:00 2001 From: "U-LAPTOP-4EP3DB2K\\alexa" Date: Mon, 23 Oct 2023 09:47:19 +0800 Subject: [PATCH 4/5] PR feedback: fix formatting --- beetsplug/discogs.py | 10 +++++----- beetsplug/fetchart.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 2063f188c..3385e4221 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -476,17 +476,17 @@ class DiscogsPlugin(BeetsPlugin): discogs_albumid=discogs_albumid, discogs_labelid=labelid, discogs_artistid=artist_id, - cover_art_url=cover_art_url + 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 + # 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): diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index e59a4ebf8..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.get('cover_art_url'): + if album.get("cover_art_url"): image_url = album.cover_art_url else: image_url = album.items().get().cover_art_url From 6e11bb5267a1b1ed43f631811244fcad7704139e Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 25 Oct 2023 14:14:51 -0400 Subject: [PATCH 5/5] Remove an errant space --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 1cdef2575..a6ae89a7a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -18,7 +18,7 @@ Major new features: New features: * :doc:`plugins/discogs`: supply a value for the `cover_art_url` attribute, for use by `fetchart`. - :bug: `429` + :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`