Make google id_from_url() more robust

This commit is contained in:
Kovid Goyal 2022-04-15 09:00:06 +05:30
parent 37c607b3f6
commit 8f9a62f2fc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -201,13 +201,13 @@ class GoogleBooks(Source):
# }}} # }}}
def id_from_url(self, url): # {{{ def id_from_url(self, url): # {{{
url_pattern = r'(?:http|https)://books\.google\.com/books\?id=(?P<id_>.+)' from polyglot.urllib import urlparse, parse_qs
url_pattern = re.compile(url_pattern) purl = urlparse(url)
id_ = url_pattern.search(url).group('id_') if purl.netloc == 'books.google.com':
if id_: q = parse_qs(purl.query)
return ('google', id_) gid = q.get('id')
else: if gid:
return None return 'google', gid[0]
# }}} # }}}
def create_query(self, title=None, authors=None, identifiers={}, capitalize_isbn=False): # {{{ def create_query(self, title=None, authors=None, identifiers={}, capitalize_isbn=False): # {{{