From 3570f5cd56425a8c347e0efe1c21f314327ae113 Mon Sep 17 00:00:00 2001 From: Mat Date: Thu, 26 Dec 2019 17:36:56 +0000 Subject: [PATCH 1/3] New high_resolution config option in fetchart --- beetsplug/fetchart.py | 16 ++++++++++++++-- docs/changelog.rst | 6 +++++- docs/plugins/fetchart.rst | 3 +++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index a815d4d9b..9cb564eaf 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -470,6 +470,14 @@ class ITunesStore(RemoteArtSource): NAME = u"iTunes Store" API_URL = u'https://itunes.apple.com/search' + def __init__(self, *args, **kwargs): + super(ITunesStore, self).__init__(*args, **kwargs) + high_resolution = self._config['high_resolution'].get() + if high_resolution: + self.image_suffix = '100000x100000-999' + else: + self.image_suffix = '1200x1200bb' + def get(self, album, plugin, paths): """Return art URL from iTunes Store given an album title. """ @@ -510,7 +518,8 @@ class ITunesStore(RemoteArtSource): if (c['artistName'] == album.albumartist and c['collectionName'] == album.album): art_url = c['artworkUrl100'] - art_url = art_url.replace('100x100', '1200x1200') + art_url = art_url.replace('100x100bb', + self.image_suffix) yield self._candidate(url=art_url, match=Candidate.MATCH_EXACT) except KeyError as e: @@ -520,7 +529,8 @@ class ITunesStore(RemoteArtSource): try: fallback_art_url = candidates[0]['artworkUrl100'] - fallback_art_url = fallback_art_url.replace('100x100', '1200x1200') + fallback_art_url = fallback_art_url.replace('100x100bb', + self.image_suffix) yield self._candidate(url=fallback_art_url, match=Candidate.MATCH_FALLBACK) except KeyError as e: @@ -774,6 +784,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): 'google_engine': u'001442825323518660753:hrh5ch1gjzm', 'fanarttv_key': None, 'store_source': False, + 'high_resolution': False, }) self.config['google_key'].redact = True self.config['fanarttv_key'].redact = True @@ -802,6 +813,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): self.cover_names = list(map(util.bytestring_path, cover_names)) self.cautious = self.config['cautious'].get(bool) self.store_source = self.config['store_source'].get(bool) + self.high_resolution = self.config['high_resolution'].get(bool) self.src_removed = (config['import']['delete'].get(bool) or config['import']['move'].get(bool)) diff --git a/docs/changelog.rst b/docs/changelog.rst index 0608fb06c..0017b98a2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,7 +6,11 @@ Changelog New features: -* :doc:`plugins/discogs` now adds two extra fields: `discogs_labelid` and +* :doc:`plugins/fetchart`: Added new ``high_resolution`` config option to + allow downloading of higher resolution iTunes artwork (at the expense of + file size) + :bug: `3391` +* :doc:`plugins/discogs` now adds two extra fields: `discogs_labelid` and `discogs_artistid` :bug: `3413` * :doc:`/plugins/export`: Added new ``-f`` (``--format``) flag; diff --git a/docs/plugins/fetchart.rst b/docs/plugins/fetchart.rst index f23fec765..c4ce189c7 100644 --- a/docs/plugins/fetchart.rst +++ b/docs/plugins/fetchart.rst @@ -67,6 +67,9 @@ file. The available options are: - **store_source**: If enabled, fetchart stores the artwork's source in a flexible tag named ``art_source``. See below for the rationale behind this. Default: ``no``. +- **high_resolution**: If enabled, fetchart retrieves artwork in the highest + resolution it can find (Warning: image files can sometimes reach >20MB) + Default: ``no``. Note: ``maxwidth`` and ``enforce_ratio`` options require either `ImageMagick`_ or `Pillow`_. From 7ad3f7f72869a34d7b762e8cf7c441407099631e Mon Sep 17 00:00:00 2001 From: Mat Date: Thu, 26 Dec 2019 21:09:26 +0000 Subject: [PATCH 2/3] Apply suggestions from code review Fix wording in docs Co-Authored-By: Adrian Sampson --- docs/changelog.rst | 4 ++-- docs/plugins/fetchart.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 0017b98a2..e8a2717c5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,9 +6,9 @@ Changelog New features: -* :doc:`plugins/fetchart`: Added new ``high_resolution`` config option to +* :doc:`plugins/fetchart`: Added a new ``high_resolution`` config option to allow downloading of higher resolution iTunes artwork (at the expense of - file size) + file size). :bug: `3391` * :doc:`plugins/discogs` now adds two extra fields: `discogs_labelid` and `discogs_artistid` diff --git a/docs/plugins/fetchart.rst b/docs/plugins/fetchart.rst index c4ce189c7..68212a582 100644 --- a/docs/plugins/fetchart.rst +++ b/docs/plugins/fetchart.rst @@ -68,7 +68,7 @@ file. The available options are: flexible tag named ``art_source``. See below for the rationale behind this. Default: ``no``. - **high_resolution**: If enabled, fetchart retrieves artwork in the highest - resolution it can find (Warning: image files can sometimes reach >20MB) + resolution it can find (warning: image files can sometimes reach >20MB). Default: ``no``. Note: ``maxwidth`` and ``enforce_ratio`` options require either `ImageMagick`_ From 2593a5be3405e9e0c9c49027d80e33e08f820a98 Mon Sep 17 00:00:00 2001 From: Mat Date: Thu, 26 Dec 2019 21:55:48 +0000 Subject: [PATCH 3/3] Use a local var to use high resolution option --- beetsplug/fetchart.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 9cb564eaf..fa43025de 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -470,14 +470,6 @@ class ITunesStore(RemoteArtSource): NAME = u"iTunes Store" API_URL = u'https://itunes.apple.com/search' - def __init__(self, *args, **kwargs): - super(ITunesStore, self).__init__(*args, **kwargs) - high_resolution = self._config['high_resolution'].get() - if high_resolution: - self.image_suffix = '100000x100000-999' - else: - self.image_suffix = '1200x1200bb' - def get(self, album, plugin, paths): """Return art URL from iTunes Store given an album title. """ @@ -513,13 +505,18 @@ class ITunesStore(RemoteArtSource): payload['term']) return + if self._config['high_resolution'].get(): + image_suffix = '100000x100000-999' + else: + image_suffix = '1200x1200bb' + for c in candidates: try: if (c['artistName'] == album.albumartist and c['collectionName'] == album.album): art_url = c['artworkUrl100'] art_url = art_url.replace('100x100bb', - self.image_suffix) + image_suffix) yield self._candidate(url=art_url, match=Candidate.MATCH_EXACT) except KeyError as e: @@ -530,7 +527,7 @@ class ITunesStore(RemoteArtSource): try: fallback_art_url = candidates[0]['artworkUrl100'] fallback_art_url = fallback_art_url.replace('100x100bb', - self.image_suffix) + image_suffix) yield self._candidate(url=fallback_art_url, match=Candidate.MATCH_FALLBACK) except KeyError as e: @@ -813,7 +810,6 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): self.cover_names = list(map(util.bytestring_path, cover_names)) self.cautious = self.config['cautious'].get(bool) self.store_source = self.config['store_source'].get(bool) - self.high_resolution = self.config['high_resolution'].get(bool) self.src_removed = (config['import']['delete'].get(bool) or config['import']['move'].get(bool))