fetchart: cover engines yield their results

This commit is contained in:
Fabrice Laporte 2014-11-10 22:17:34 +01:00
parent 5713df3d5a
commit ef6d3efe6d
2 changed files with 9 additions and 9 deletions

View file

@ -126,7 +126,7 @@ def aao_art(album):
m = re.search(AAO_PAT, resp.text) m = re.search(AAO_PAT, resp.text)
if m: if m:
image_url = m.group(1) image_url = m.group(1)
return image_url yield image_url
else: else:
log.debug(u'fetchart: no image found on page') log.debug(u'fetchart: no image found on page')
@ -155,7 +155,7 @@ def google_art(album):
data = results['responseData'] data = results['responseData']
dataInfo = data['results'] dataInfo = data['results']
for myUrl in dataInfo: for myUrl in dataInfo:
return myUrl['unescapedUrl'] yield myUrl['unescapedUrl']
except: except:
log.debug(u'fetchart: error scraping art page') log.debug(u'fetchart: error scraping art page')
return return
@ -172,7 +172,7 @@ def itunes_art(album):
if itunes_album.get_artwork()['100']: if itunes_album.get_artwork()['100']:
small_url = itunes_album.get_artwork()['100'] small_url = itunes_album.get_artwork()['100']
big_url = small_url.replace('100x100', '1200x1200') big_url = small_url.replace('100x100', '1200x1200')
return big_url yield big_url
else: else:
log.debug(u'fetchart: album has no artwork in iTunes Store') log.debug(u'fetchart: album has no artwork in iTunes Store')
except IndexError: except IndexError:
@ -181,6 +181,7 @@ def itunes_art(album):
# Art from the filesystem. # Art from the filesystem.
def filename_priority(filename, cover_names): def filename_priority(filename, cover_names):
"""Sort order for image names. """Sort order for image names.
@ -244,9 +245,8 @@ def _source_urls(album, sources=SOURCES_ALL):
""" """
for s in sources: for s in sources:
urls = ART_FUNCS[s](album) urls = ART_FUNCS[s](album)
if urls: for url in urls:
for url in urls: yield url
yield url
def art_for_album(album, paths, maxwidth=None, local_only=False): def art_for_album(album, paths, maxwidth=None, local_only=False):

View file

@ -198,13 +198,13 @@ class AAOTest(_common.TestCase):
self.mock_response(self.AAO_URL, body) self.mock_response(self.AAO_URL, body)
album = _common.Bag(asin=self.ASIN) album = _common.Bag(asin=self.ASIN)
res = fetchart.aao_art(album) 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') self.mock_response(self.AAO_URL, 'blah blah')
album = _common.Bag(asin=self.ASIN) album = _common.Bag(asin=self.ASIN)
res = fetchart.aao_art(album) res = fetchart.aao_art(album)
self.assertEqual(res, None) self.assertEqual(list(res), [])
class GoogleImageTest(_common.TestCase): class GoogleImageTest(_common.TestCase):