From c67412e1cf35a217f72c377be8e6d2ecf11df6ad Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Nov 2023 08:23:25 +0530 Subject: [PATCH] Update the date in the Google consent cookie --- src/calibre/ebooks/metadata/sources/google_images.py | 8 ++++++-- src/calibre/ebooks/metadata/sources/search_engines.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/google_images.py b/src/calibre/ebooks/metadata/sources/google_images.py index 08e17546fa..08631e082e 100644 --- a/src/calibre/ebooks/metadata/sources/google_images.py +++ b/src/calibre/ebooks/metadata/sources/google_images.py @@ -46,7 +46,7 @@ def imgurl_from_id(raw, tbnid): class GoogleImages(Source): name = 'Google Images' - version = (1, 0, 4) + version = (1, 0, 5) minimum_calibre_version = (2, 80, 0) description = _('Downloads covers from a Google Image search. Useful to find larger/alternate covers.') capabilities = frozenset(['cover']) @@ -107,7 +107,11 @@ class GoogleImages(Source): log('Search URL: ' + url) # See https://github.com/benbusby/whoogle-search/pull/1054 for cookies br.set_simple_cookie('CONSENT', 'PENDING+987', '.google.com', path='/') - br.set_simple_cookie('SOCS','CAESHAgBEhJnd3NfMjAyMzA4MTAtMF9SQzIaAmRlIAEaBgiAo_CmBg', '.google.com', path='/') + template = b'\x08\x01\x128\x08\x14\x12+boq_identityfrontenduiserver_20231107.05_p0\x1a\x05en-US \x03\x1a\x06\x08\x80\xf1\xca\xaa\x06' + from datetime import date + from base64 import standard_b64encode + template.replace(b'20231107', date.today().strftime('%Y%m%d').encode('ascii')) + br.set_simple_cookie('SOCS', standard_b64encode(template).decode('ascii').rstrip('='), '.google.com', path='/') # br.set_debug_http(True) raw = clean_ascii_chars(br.open(url).read().decode('utf-8')) # with open('/t/raw.html', 'w') as f: diff --git a/src/calibre/ebooks/metadata/sources/search_engines.py b/src/calibre/ebooks/metadata/sources/search_engines.py index 856be16f74..31375a663f 100644 --- a/src/calibre/ebooks/metadata/sources/search_engines.py +++ b/src/calibre/ebooks/metadata/sources/search_engines.py @@ -27,7 +27,7 @@ from calibre.ebooks.chardet import xml_to_unicode from calibre.utils.lock import ExclusiveFile from calibre.utils.random_ua import accept_header_for_ua -current_version = (1, 2, 3) +current_version = (1, 2, 4) minimum_calibre_version = (2, 80, 0) webcache = {} webcache_lock = Lock() @@ -370,7 +370,11 @@ def google_specialize_browser(br): if not hasattr(br, 'google_consent_cookie_added'): # See https://github.com/benbusby/whoogle-search/pull/1054 for cookies br.set_simple_cookie('CONSENT', 'PENDING+987', '.google.com', path='/') - br.set_simple_cookie('SOCS','CAESHAgBEhJnd3NfMjAyMzA4MTAtMF9SQzIaAmRlIAEaBgiAo_CmBg', '.google.com', path='/') + template = b'\x08\x01\x128\x08\x14\x12+boq_identityfrontenduiserver_20231107.05_p0\x1a\x05en-US \x03\x1a\x06\x08\x80\xf1\xca\xaa\x06' + from datetime import date + from base64 import standard_b64encode + template.replace(b'20231107', date.today().strftime('%Y%m%d').encode('ascii')) + br.set_simple_cookie('SOCS', standard_b64encode(template).decode('ascii').rstrip('='), '.google.com', path='/') br.google_consent_cookie_added = True return br