From f5446f68a7e64f14e526c06256ddac679374e328 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 16 Jun 2017 14:04:37 +0530 Subject: [PATCH] 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) --- src/calibre/ebooks/metadata/sources/google_images.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/google_images.py b/src/calibre/ebooks/metadata/sources/google_images.py index 1903fd6ec3..436540ace5 100644 --- a/src/calibre/ebooks/metadata/sources/google_images.py +++ b/src/calibre/ebooks/metadata/sources/google_images.py @@ -9,10 +9,9 @@ __docformat__ = 'restructuredtext en' from collections import OrderedDict +from calibre import random_user_agent 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): @@ -51,7 +50,7 @@ class GoogleImages(Source): @property def user_agent(self): - return USER_AGENT + return random_user_agent(allow_ie=False) def get_image_urls(self, title, author, log, abort, timeout): from calibre.utils.cleantext import clean_ascii_chars @@ -75,7 +74,7 @@ class GoogleImages(Source): log('Search URL: ' + url) raw = br.open(url).read().decode('utf-8') 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: data = json.loads(div.text) except Exception: