From 8f9a62f2fc5245932ae912af58a6a3f4780c5132 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Apr 2022 09:00:06 +0530 Subject: [PATCH] Make google id_from_url() more robust --- src/calibre/ebooks/metadata/sources/google.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/google.py b/src/calibre/ebooks/metadata/sources/google.py index 2ed312dd76..23b79dbd67 100644 --- a/src/calibre/ebooks/metadata/sources/google.py +++ b/src/calibre/ebooks/metadata/sources/google.py @@ -201,13 +201,13 @@ class GoogleBooks(Source): # }}} def id_from_url(self, url): # {{{ - url_pattern = r'(?:http|https)://books\.google\.com/books\?id=(?P.+)' - url_pattern = re.compile(url_pattern) - id_ = url_pattern.search(url).group('id_') - if id_: - return ('google', id_) - else: - return None + from polyglot.urllib import urlparse, parse_qs + purl = urlparse(url) + if purl.netloc == 'books.google.com': + q = parse_qs(purl.query) + gid = q.get('id') + if gid: + return 'google', gid[0] # }}} def create_query(self, title=None, authors=None, identifiers={}, capitalize_isbn=False): # {{{