From ac2f7fe7127150d2ce0f84890380a2aedd79bc16 Mon Sep 17 00:00:00 2001 From: wordofglass Date: Wed, 20 Apr 2016 12:59:18 +0200 Subject: [PATCH] Fix the fanarttv source failing when there were images found, but no cover art --- beetsplug/fetchart.py | 12 ++++++------ test/test_art.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index db4d0034e..797d774c4 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -395,12 +395,12 @@ class FanartTV(RemoteArtSource): return matches = [] - # can there be more than one releasegroupid per responce? - for mb_releasegroupid in data.get(u'albums', dict()): - if album.mb_releasegroupid == mb_releasegroupid: - # note: there might be more art referenced, e.g. cdart - matches.extend( - data[u'albums'][mb_releasegroupid][u'albumcover']) + # can there be more than one releasegroupid per response? + for mbid, art in data.get(u'albums', dict()).items(): + # there might be more art referenced, e.g. cdart, and an albumcover + # might not be present, even if the request was succesful + if album.mb_releasegroupid == mbid and u'albumcover' in art: + matches.extend(art[u'albumcover']) # can this actually occur? else: self._log.debug(u'fanart.tv: unexpected mb_releasegroupid in ' diff --git a/test/test_art.py b/test/test_art.py index 2e7db8439..3014707a8 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -315,6 +315,23 @@ class FanartTVTest(UseThePlugin): } } }""" + RESPONSE_NO_ART = u"""{ + "name": "artistname", + "mbid_id": "artistid", + "albums": { + "thereleasegroupid": { + "cdart": [ + { + "id": "123", + "url": "http://example.com/4.jpg", + "likes": "0", + "disc": "1", + "size": "1000" + } + ] + } + } + }""" RESPONSE_ERROR = u"""{ "status": "error", "error message": "the error message" @@ -355,6 +372,14 @@ class FanartTVTest(UseThePlugin): with self.assertRaises(StopIteration): next(self.source.get(album, self.extra)) + def test_fanarttv_only_other_images(self): + # The source used to fail when there were images present, but no cover + album = _common.Bag(mb_releasegroupid=u'thereleasegroupid') + self.mock_response(fetchart.FanartTV.API_ALBUMS + u'thereleasegroupid', + self.RESPONSE_NO_ART) + with self.assertRaises(StopIteration): + next(self.source.get(album, self.extra)) + @_common.slow_test() class ArtImporterTest(UseThePlugin):