mirror of
https://github.com/beetbox/beets.git
synced 2026-02-23 07:44:38 +01:00
Merge branch 'Lemutar-master'
This commit is contained in:
commit
7f675dbf64
3 changed files with 67 additions and 0 deletions
|
|
@ -122,6 +122,26 @@ def aao_art(asin):
|
|||
else:
|
||||
log.debug(u'fetchart: no image found on page')
|
||||
|
||||
# googleapis.org scraper.
|
||||
|
||||
GOOGLE_URL = 'https://ajax.googleapis.com/ajax/services/search/images'
|
||||
|
||||
def google_art(album):
|
||||
"""Return art URL from google.org given an album title and interpreter"""
|
||||
|
||||
search_string = (album.albumartist + ',' + album.album).encode('utf-8')
|
||||
response = requests_session.get(GOOGLE_URL, params={'v': '1.0','q': search_string, 'start':'0'})
|
||||
# Get results using JSON
|
||||
try:
|
||||
results = response.json()
|
||||
data = results['responseData']
|
||||
dataInfo = data['results']
|
||||
for myUrl in dataInfo:
|
||||
return myUrl['unescapedUrl']
|
||||
except:
|
||||
log.debug(u'fetchart: error scraping art page')
|
||||
return
|
||||
|
||||
|
||||
# Art from the filesystem.
|
||||
|
||||
|
|
@ -179,6 +199,12 @@ def _source_urls(album):
|
|||
if url:
|
||||
yield url
|
||||
|
||||
google_search = config['fetchart']['google_search'].get(bool)
|
||||
if google_search == True:
|
||||
url = google_art(album)
|
||||
if url:
|
||||
yield url
|
||||
|
||||
|
||||
def art_for_album(album, paths, maxwidth=None, local_only=False):
|
||||
"""Given an Album object, returns a path to downloaded art for the
|
||||
|
|
@ -251,6 +277,7 @@ class FetchArtPlugin(BeetsPlugin):
|
|||
'maxwidth': 0,
|
||||
'remote_priority': False,
|
||||
'cautious': False,
|
||||
'google_search' : False,
|
||||
'cover_names': ['cover', 'front', 'art', 'album', 'folder'],
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -96,6 +96,21 @@ When you choose to apply changes during an import, beets will search for art as
|
|||
described above. For "as-is" imports (and non-autotagged imports using the
|
||||
``-A`` flag), beets only looks for art on the local filesystem.
|
||||
|
||||
Album Art with Google Image Search
|
||||
-----------------------------------
|
||||
|
||||
If no art is found on the common sources there is the possibility get "the" or "a" album
|
||||
art form google image search.
|
||||
|
||||
If enabled this function take the first hit with the search text "<artist>,<album_name>" on google image search as album art
|
||||
|
||||
To enable art gathering form google, just put this in your configuration
|
||||
file::
|
||||
|
||||
fetchart:
|
||||
google_search: true
|
||||
|
||||
|
||||
Embedding Album Art
|
||||
-------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -187,7 +187,32 @@ class AAOTest(_common.TestCase):
|
|||
self.mock_response(self.AAO_URL, 'blah blah')
|
||||
res = fetchart.aao_art(self.ASIN)
|
||||
self.assertEqual(res, None)
|
||||
|
||||
class GoogleImageTest(_common.TestCase):
|
||||
|
||||
GOOGLE_URL = 'https://ajax.googleapis.com/ajax/services/search/images'
|
||||
|
||||
@responses.activate
|
||||
def run(self, *args, **kwargs):
|
||||
super(GoogleImageTest, self).run(*args, **kwargs)
|
||||
|
||||
def mock_response(self, url, json):
|
||||
responses.add(responses.GET, url, body=json, content_type='application/json')
|
||||
|
||||
|
||||
def test_google_art_finds_image(self):
|
||||
album = _common.Bag(albumartist="some artist",album="some album")
|
||||
json = """{"responseData": {"results": [{"unescapedUrl": "url_to_the_image"}]}}"""
|
||||
self.mock_response(self.GOOGLE_URL, json)
|
||||
result_url = fetchart.google_art(album)
|
||||
self.assertEqual(result_url, 'url_to_the_image')
|
||||
|
||||
def test_google_art_dont_finds_image(self):
|
||||
album = _common.Bag(albumartist="some artist",album="some album")
|
||||
json = """bla blup"""
|
||||
self.mock_response(self.GOOGLE_URL, json)
|
||||
result_url = fetchart.google_art(album)
|
||||
self.assertEqual(result_url, None)
|
||||
|
||||
class ArtImporterTest(_common.TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue