From ef6d3efe6d6adf4595b1b673dba37af48f1359e6 Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Mon, 10 Nov 2014 22:17:34 +0100 Subject: [PATCH] fetchart: cover engines yield their results --- beetsplug/fetchart.py | 12 ++++++------ test/test_art.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index fb4eac5de..18ffe7790 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -126,7 +126,7 @@ def aao_art(album): m = re.search(AAO_PAT, resp.text) if m: image_url = m.group(1) - return image_url + yield image_url else: log.debug(u'fetchart: no image found on page') @@ -155,7 +155,7 @@ def google_art(album): data = results['responseData'] dataInfo = data['results'] for myUrl in dataInfo: - return myUrl['unescapedUrl'] + yield myUrl['unescapedUrl'] except: log.debug(u'fetchart: error scraping art page') return @@ -172,7 +172,7 @@ def itunes_art(album): if itunes_album.get_artwork()['100']: small_url = itunes_album.get_artwork()['100'] big_url = small_url.replace('100x100', '1200x1200') - return big_url + yield big_url else: log.debug(u'fetchart: album has no artwork in iTunes Store') except IndexError: @@ -181,6 +181,7 @@ def itunes_art(album): # Art from the filesystem. + def filename_priority(filename, cover_names): """Sort order for image names. @@ -244,9 +245,8 @@ def _source_urls(album, sources=SOURCES_ALL): """ for s in sources: urls = ART_FUNCS[s](album) - if urls: - for url in urls: - yield url + for url in urls: + yield url def art_for_album(album, paths, maxwidth=None, local_only=False): diff --git a/test/test_art.py b/test/test_art.py index 62226de8d..33a7826bf 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -198,13 +198,13 @@ class AAOTest(_common.TestCase): self.mock_response(self.AAO_URL, body) album = _common.Bag(asin=self.ASIN) res = fetchart.aao_art(album) - self.assertEqual(res, 'TARGET_URL') + self.assertEqual(list(res)[0], 'TARGET_URL') - def test_aao_scraper_returns_none_when_no_image_present(self): + def test_aao_scraper_returns_no_result_when_no_image_present(self): self.mock_response(self.AAO_URL, 'blah blah') album = _common.Bag(asin=self.ASIN) res = fetchart.aao_art(album) - self.assertEqual(res, None) + self.assertEqual(list(res), []) class GoogleImageTest(_common.TestCase):