From e0fe581d1d9bcb8897a61017bf75395ea00b922c Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Thu, 14 Apr 2022 18:14:30 +0100 Subject: [PATCH] Add id_from_url() to the Google metadata source --- src/calibre/ebooks/metadata/sources/google.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/calibre/ebooks/metadata/sources/google.py b/src/calibre/ebooks/metadata/sources/google.py index af380836f4..e2f0991e1a 100644 --- a/src/calibre/ebooks/metadata/sources/google.py +++ b/src/calibre/ebooks/metadata/sources/google.py @@ -198,7 +198,16 @@ class GoogleBooks(Source): goog = identifiers.get('google', None) if goog is not None: return ('google', goog, 'https://books.google.com/books?id=%s' % goog) + # }}} + def id_from_url(self, url): # {{{ + url_pattern = '(?: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 # }}} def create_query(self, title=None, authors=None, identifiers={}, capitalize_isbn=False): # {{{