Fix the error with CAA where no image would be downloaded when thumbnails are missing

This commit is contained in:
AdrienCos 2023-10-07 22:48:45 +02:00
parent e7105a9763
commit 96b89e77f6
3 changed files with 82 additions and 4 deletions

View file

@ -399,10 +399,15 @@ class CoverArtArchive(RemoteArtSource):
if 'Front' not in item['types']:
continue
if preferred_width:
yield item['thumbnails'][preferred_width]
else:
yield item['image']
# If there is a pre-sized thumbnail of the desired size
# we select it. Otherwise, we return the raw image.
image_url: str = item["image"]
if preferred_width is not None:
if isinstance(item.get("thumbnails"), dict):
image_url = item["thumbnails"].get(
preferred_width, image_url
)
yield image_url
except KeyError:
pass

View file

@ -128,6 +128,9 @@ New features:
* :doc:`/plugins/fetchart`: Fix the error with CoverArtArchive where the
`maxwidth` option would not be used to download a pre-sized thumbnail for
release groups, as is already done with releases.
* :doc:`/plugins/fetchart`: Fix the error with CoverArtArchive where no cover
would be found when the `maxwidth` option matches a pre-sized thumbnail size,
but no thumbnail is provided by CAA. We now fallback to the raw image.
Bug fixes:

View file

@ -130,6 +130,39 @@ class CAAHelper():
}
],
"release": "https://musicbrainz.org/release/releaseid"
}"""
RESPONSE_RELEASE_WITHOUT_THUMBNAILS = """{
"images": [
{
"approved": false,
"back": false,
"comment": "GIF",
"edit": 12345,
"front": true,
"id": 12345,
"image": "http://coverartarchive.org/release/rid/12345.gif",
"types": [
"Front"
]
},
{
"approved": false,
"back": false,
"comment": "",
"edit": 12345,
"front": false,
"id": 12345,
"image": "http://coverartarchive.org/release/rid/12345.jpg",
"thumbnails": {
"large": "http://coverartarchive.org/release/rgid/12345-500.jpg",
"small": "http://coverartarchive.org/release/rgid/12345-250.jpg"
},
"types": [
"Front"
]
}
],
"release": "https://musicbrainz.org/release/releaseid"
}"""
RESPONSE_GROUP = """{
"images": [
@ -155,6 +188,23 @@ class CAAHelper():
],
"release": "https://musicbrainz.org/release/release-id"
}"""
RESPONSE_GROUP_WITHOUT_THUMBNAILS = """{
"images": [
{
"approved": false,
"back": false,
"comment": "",
"edit": 12345,
"front": true,
"id": 12345,
"image": "http://coverartarchive.org/release/releaseid/12345.jpg",
"types": [
"Front"
]
}
],
"release": "https://musicbrainz.org/release/release-id"
}"""
def mock_caa_response(self, url, json):
responses.add(responses.GET, url, body=json,
@ -537,6 +587,26 @@ class CoverArtArchiveTest(UseThePlugin, CAAHelper):
for candidate in candidates:
self.assertTrue(f"-{maxwidth}.jpg" in candidate.url)
def test_caa_finds_image_if_maxwidth_is_set_and_thumbnails_is_empty(self):
# CAA provides pre-sized thumbnails of width 250px, 500px, and 1200px
# We only test with one of them here
maxwidth = 1200
self.settings = Settings(maxwidth=maxwidth)
album = _common.Bag(
mb_albumid=self.MBID_RELASE, mb_releasegroupid=self.MBID_GROUP
)
self.mock_caa_response(
self.RELEASE_URL, self.RESPONSE_RELEASE_WITHOUT_THUMBNAILS
)
self.mock_caa_response(
self.GROUP_URL, self.RESPONSE_GROUP_WITHOUT_THUMBNAILS,
)
candidates = list(self.source.get(album, self.settings, []))
self.assertEqual(len(candidates), 3)
for candidate in candidates:
self.assertFalse(f"-{maxwidth}.jpg" in candidate.url)
class FanartTVTest(UseThePlugin):
RESPONSE_MULTIPLE = """{