mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Google images metadata download plugin: Fix for change in website causing no covers to be downloaded
Fixes #1698314 [Google Images plugin can't find any images](https://bugs.launchpad.net/calibre/+bug/1698314)
This commit is contained in:
parent
bc6656c801
commit
f5446f68a7
@ -9,10 +9,9 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from calibre import random_user_agent
|
||||||
from calibre.ebooks.metadata.sources.base import Source, Option
|
from calibre.ebooks.metadata.sources.base import Source, Option
|
||||||
|
|
||||||
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0'
|
|
||||||
|
|
||||||
|
|
||||||
class GoogleImages(Source):
|
class GoogleImages(Source):
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ class GoogleImages(Source):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def user_agent(self):
|
def user_agent(self):
|
||||||
return USER_AGENT
|
return random_user_agent(allow_ie=False)
|
||||||
|
|
||||||
def get_image_urls(self, title, author, log, abort, timeout):
|
def get_image_urls(self, title, author, log, abort, timeout):
|
||||||
from calibre.utils.cleantext import clean_ascii_chars
|
from calibre.utils.cleantext import clean_ascii_chars
|
||||||
@ -75,7 +74,7 @@ class GoogleImages(Source):
|
|||||||
log('Search URL: ' + url)
|
log('Search URL: ' + url)
|
||||||
raw = br.open(url).read().decode('utf-8')
|
raw = br.open(url).read().decode('utf-8')
|
||||||
root = html5lib.parse(clean_ascii_chars(raw), treebuilder='lxml', namespaceHTMLElements=False)
|
root = html5lib.parse(clean_ascii_chars(raw), treebuilder='lxml', namespaceHTMLElements=False)
|
||||||
for div in root.xpath('//div[@class="rg_meta"]'):
|
for div in root.xpath('//div[@class="rg_meta notranslate"]'):
|
||||||
try:
|
try:
|
||||||
data = json.loads(div.text)
|
data = json.loads(div.text)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user