From 3bcd7058cd71c6892512640165e0c3a286404630 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Fri, 6 Aug 2021 18:01:28 +0200 Subject: [PATCH] amazon: fall back to try loading cover only by ASIN Having the full Amazon URL is preferrable, as the correct image path can be deduced from the Amazon host. But if relationships are not available, try all the different hosts --- plugins/amazon/amazon.py | 42 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/plugins/amazon/amazon.py b/plugins/amazon/amazon.py index d2f0b90b..351b1663 100644 --- a/plugins/amazon/amazon.py +++ b/plugins/amazon/amazon.py @@ -2,7 +2,7 @@ # # Picard, the next-generation MusicBrainz tagger # Copyright (C) 2007 Oliver Charles -# Copyright (C) 2007-2011, 2019 Philipp Wolfer +# Copyright (C) 2007-2011, 2019, 2021 Philipp Wolfer # Copyright (C) 2007, 2010, 2011 Lukáš Lalinský # Copyright (C) 2011 Michael Wiencek # Copyright (C) 2011-2012 Wieland Hoffmann @@ -25,8 +25,8 @@ PLUGIN_NAME = 'Amazon cover art' PLUGIN_AUTHOR = 'MusicBrainz Picard developers' PLUGIN_DESCRIPTION = 'Use cover art from Amazon.' -PLUGIN_VERSION = "1.0" -PLUGIN_API_VERSIONS = ["2.2"] +PLUGIN_VERSION = "1.1" +PLUGIN_API_VERSIONS = ["2.2", "2.3", "2.4", "2.5", "2.6", "2.7"] PLUGIN_LICENSE = "GPL-2.0-or-later" PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-2.0.html" @@ -44,6 +44,10 @@ # Releases not sold on amazon.com, don't have a "01"-version of the image, # so we need to make sure we grab an existing image. AMAZON_SERVER = { + "amazon.com": { + "server": "ec1.images-amazon.com", + "id": "01", + }, "amazon.jp": { "server": "ec1.images-amazon.com", "id": "09", @@ -60,10 +64,6 @@ "server": "ec2.images-amazon.com", "id": "03", }, - "amazon.com": { - "server": "ec1.images-amazon.com", - "id": "01", - }, "amazon.ca": { "server": "ec1.images-amazon.com", "id": "01", # .com and .ca are identical @@ -99,6 +99,10 @@ class CoverArtProviderAmazon(CoverArtProvider): NAME = "Amazon" TITLE = N_('Amazon') + def __init__(self, coverart): + super().__init__(coverart) + self._has_url_relation = False + def enabled(self): return (super().enabled() and not self.coverart.front_image_found) @@ -106,6 +110,9 @@ def enabled(self): def queue_images(self): self.match_url_relations(('amazon asin', 'has_Amazon_ASIN'), self._queue_from_asin_relation) + # No URL relationships loaded, try by ASIN + if not self._has_url_relation: + self._queue_from_asin() return CoverArtProvider.FINISHED def _queue_from_asin_relation(self, url): @@ -114,15 +121,26 @@ def _queue_from_asin_relation(self, url): if amz is None: return log.debug("Found ASIN relation : %s %s", amz['host'], amz['asin']) + self._has_url_relation = True if amz['host'] in AMAZON_SERVER: - serverInfo = AMAZON_SERVER[amz['host']] + server_info = AMAZON_SERVER[amz['host']] else: - serverInfo = AMAZON_SERVER['amazon.com'] - host = serverInfo['server'] + server_info = AMAZON_SERVER['amazon.com'] + self._queue_asin(server_info, amz['asin']) + + def _queue_from_asin(self): + asin = self.release.get('asin') + if asin: + log.debug("Found ASIN : %s", asin) + for server_info in AMAZON_SERVER.values(): + self._queue_asin(server_info, asin) + + def _queue_asin(self, server_info, asin): + host = server_info['server'] for size in AMAZON_SIZES: path = AMAZON_IMAGE_PATH % { - 'asin': amz['asin'], - 'serverid': serverInfo['id'], + 'asin': asin, + 'serverid': server_info['id'], 'size': size } self.queue_put(CoverArtImage("http://%s%s" % (host, path)))