mirror of
https://github.com/beetbox/beets.git
synced 2026-02-22 07:14:24 +01:00
Style and wording for Google Images (#766)
This commit is contained in:
parent
7f675dbf64
commit
dfa8445980
4 changed files with 38 additions and 24 deletions
|
|
@ -122,16 +122,24 @@ def aao_art(asin):
|
|||
else:
|
||||
log.debug(u'fetchart: no image found on page')
|
||||
|
||||
# googleapis.org scraper.
|
||||
|
||||
# Google Images 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"""
|
||||
|
||||
"""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
|
||||
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']
|
||||
|
|
@ -199,8 +207,7 @@ def _source_urls(album):
|
|||
if url:
|
||||
yield url
|
||||
|
||||
google_search = config['fetchart']['google_search'].get(bool)
|
||||
if google_search == True:
|
||||
if config['fetchart']['google_search']:
|
||||
url = google_art(album)
|
||||
if url:
|
||||
yield url
|
||||
|
|
@ -277,7 +284,7 @@ class FetchArtPlugin(BeetsPlugin):
|
|||
'maxwidth': 0,
|
||||
'remote_priority': False,
|
||||
'cautious': False,
|
||||
'google_search' : False,
|
||||
'google_search': False,
|
||||
'cover_names': ['cover', 'front', 'art', 'album', 'folder'],
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ Changelog
|
|||
* Compatibility with the latest version of Mutagen, 1.23.
|
||||
* Support for AIFF files. Tags are stored as ID3 frames in one of the file's
|
||||
IFF chunks.
|
||||
* :doc:`/plugins/fetchart`: You can now optionally search for cover art on
|
||||
Google Image Search. Thanks to Lemutar.
|
||||
|
||||
|
||||
1.3.6 (May 10, 2014)
|
||||
|
|
|
|||
|
|
@ -96,16 +96,18 @@ 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
|
||||
-----------------------------------
|
||||
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.
|
||||
You can optionally search for cover art on `Google Images`_. This option uses
|
||||
the first hit for a search query consisting of the artist and album name. It
|
||||
is therefore approximate: "incorrect" image matches are possible (although
|
||||
unlikely).
|
||||
|
||||
If enabled this function take the first hit with the search text "<artist>,<album_name>" on google image search as album art
|
||||
.. _Google Images: http://images.google.com/
|
||||
|
||||
To enable art gathering form google, just put this in your configuration
|
||||
file::
|
||||
To enable gathering art from Google, enable the ``google_search`` option in
|
||||
your config file::
|
||||
|
||||
fetchart:
|
||||
google_search: true
|
||||
|
|
|
|||
|
|
@ -187,33 +187,36 @@ 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'
|
||||
_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')
|
||||
|
||||
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)
|
||||
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")
|
||||
album = _common.Bag(albumartist="some artist", album="some album")
|
||||
json = """bla blup"""
|
||||
self.mock_response(self.GOOGLE_URL, json)
|
||||
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):
|
||||
super(ArtImporterTest, self).setUp()
|
||||
|
|
|
|||
Loading…
Reference in a new issue