From dc622318abf04565bf7defbcd0405484bc5b39d6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 May 2016 07:24:41 +0530 Subject: [PATCH] Google Images metadata download plugin: Fix error when searching for books with non-English characters in the title or author names. Fixes #1577036 ["KeyError" during search cover in the "Google Images Covers"](https://bugs.launchpad.net/calibre/+bug/1577036) --- src/calibre/ebooks/metadata/sources/google_images.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/google_images.py b/src/calibre/ebooks/metadata/sources/google_images.py index 5494b9c793..383fb09b94 100644 --- a/src/calibre/ebooks/metadata/sources/google_images.py +++ b/src/calibre/ebooks/metadata/sources/google_images.py @@ -53,13 +53,13 @@ class GoogleImages(Source): def get_image_urls(self, title, author, log, abort, timeout): from calibre.utils.cleantext import clean_ascii_chars - from urllib import quote_plus + from urllib import urlencode import html5lib import json from collections import OrderedDict ans = OrderedDict() br = self.browser - q = quote_plus('%s %s'%(title, author)) + q = urlencode({'as_q': ('%s %s'%(title, author)).encode('utf-8')}).decode('utf-8') sz = self.prefs['size'] if sz == 'any': sz = '' @@ -69,7 +69,7 @@ class GoogleImages(Source): sz = 'isz:lt,islt:%s,' % sz # See https://www.google.com/advanced_image_search to understand this # URL scheme - url = 'https://www.google.com/search?as_st=y&tbm=isch&as_q={}&as_epq=&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs={}iar:t,ift:jpg'.format(q, sz) + url = 'https://www.google.com/search?as_st=y&tbm=isch&{}&as_epq=&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs={}iar:t,ift:jpg'.format(q, sz) log('Search URL: ' + url) raw = br.open(url).read().decode('utf-8') root = html5lib.parse(clean_ascii_chars(raw), treebuilder='lxml', namespaceHTMLElements=False)