fix google book cover

This commit is contained in:
Your Name 2023-02-12 21:54:21 -05:00 committed by Henri Dickson
parent 5224f57ad0
commit 2fe500fbdb
2 changed files with 13 additions and 4 deletions

View file

@ -231,8 +231,10 @@ class ImageDownloaderMixin:
return RESPONSE_NETWORK_ERROR
@classmethod
def download_image(cls, image_url, page_url):
def download_image(cls, image_url, page_url, headers=None):
imgdl = cls(image_url, page_url)
if headers is not None:
imgdl.headers = headers
try:
image = imgdl.download().content
image_extention = imgdl.extention

View file

@ -56,8 +56,15 @@ class GoogleBooks(AbstractSite):
brief = re.sub(r"<.*?>", "", brief.replace("<br", "\n<br"))
img_url = None
if "imageLinks" in b["volumeInfo"]:
img_url = b["volumeInfo"]["imageLinks"]["thumbnail"]
img_url = img_url.replace("zoom=1", "")
# if "extraLarge" in b["volumeInfo"]["imageLinks"]:
# img_url = b["volumeInfo"]["imageLinks"]["extraLarge"]
# elif "large" in b["volumeInfo"]["imageLinks"]:
# img_url = b["volumeInfo"]["imageLinks"]["large"]
# elif "thumbnail" in b["volumeInfo"]["imageLinks"]:
# img_url = b["volumeInfo"]["imageLinks"]["thumbnail"]
if "thumbnail" in b["volumeInfo"]["imageLinks"]:
img_url = b["volumeInfo"]["imageLinks"]["thumbnail"]
img_url = img_url.replace("zoom=1", "")
isbn10 = None
isbn13 = None
for iid in (
@ -71,7 +78,7 @@ class GoogleBooks(AbstractSite):
isbn13 = iid["identifier"]
isbn = isbn13 # if isbn13 is not None else isbn10
raw_img, ext = BasicImageDownloader.download_image(img_url, self.url)
raw_img, ext = BasicImageDownloader.download_image(img_url, None, headers={})
data = {
"title": title,
"subtitle": subtitle,