improve google book cover image quality
This commit is contained in:
parent
c6ecbd38c1
commit
5224f57ad0
3 changed files with 20 additions and 13 deletions
|
@ -47,6 +47,8 @@ def get_mock_file(url):
|
|||
fn = url.replace("***REMOVED***", "1234") # Thank you, Github Action -_-!
|
||||
fn = re.sub(r"[^\w]", "_", fn)
|
||||
fn = re.sub(r"_key_[*A-Za-z0-9]+", "_key_8964", fn)
|
||||
if len(fn) > 255:
|
||||
fn = fn[:255]
|
||||
return fn
|
||||
|
||||
|
||||
|
@ -107,12 +109,15 @@ class BasicDownloader:
|
|||
url, headers=self.headers, timeout=self.get_timeout()
|
||||
)
|
||||
if settings.DOWNLOADER_SAVEDIR:
|
||||
with open(
|
||||
settings.DOWNLOADER_SAVEDIR + "/" + get_mock_file(url),
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
) as fp:
|
||||
fp.write(resp.text)
|
||||
try:
|
||||
with open(
|
||||
settings.DOWNLOADER_SAVEDIR + "/" + get_mock_file(url),
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
) as fp:
|
||||
fp.write(resp.text)
|
||||
except:
|
||||
_logger.warn("Save downloaded data failed.")
|
||||
else:
|
||||
resp = MockResponse(self.url)
|
||||
response_type = self.validate_response(resp)
|
||||
|
@ -225,8 +230,6 @@ class ImageDownloaderMixin:
|
|||
else:
|
||||
return RESPONSE_NETWORK_ERROR
|
||||
|
||||
|
||||
class BasicImageDownloader(ImageDownloaderMixin, BasicDownloader):
|
||||
@classmethod
|
||||
def download_image(cls, image_url, page_url):
|
||||
imgdl = cls(image_url, page_url)
|
||||
|
@ -238,6 +241,10 @@ class BasicImageDownloader(ImageDownloaderMixin, BasicDownloader):
|
|||
return None, None
|
||||
|
||||
|
||||
class BasicImageDownloader(ImageDownloaderMixin, BasicDownloader):
|
||||
pass
|
||||
|
||||
|
||||
class ProxiedImageDownloader(ImageDownloaderMixin, ProxiedDownloader):
|
||||
pass
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ class Command(BaseCommand):
|
|||
resource = site.get_resource_ready(ignore_existing_content=options["force"])
|
||||
pprint.pp(resource.metadata)
|
||||
pprint.pp(site.get_item())
|
||||
pprint.pp(site.get_item().cover)
|
||||
pprint.pp(site.get_item().metadata)
|
||||
else:
|
||||
resource = site.scrape()
|
||||
|
|
|
@ -54,11 +54,10 @@ class GoogleBooks(AbstractSite):
|
|||
else:
|
||||
brief = ""
|
||||
brief = re.sub(r"<.*?>", "", brief.replace("<br", "\n<br"))
|
||||
img_url = (
|
||||
b["volumeInfo"]["imageLinks"]["thumbnail"]
|
||||
if "imageLinks" in b["volumeInfo"]
|
||||
else None
|
||||
)
|
||||
img_url = None
|
||||
if "imageLinks" in b["volumeInfo"]:
|
||||
img_url = b["volumeInfo"]["imageLinks"]["thumbnail"]
|
||||
img_url = img_url.replace("zoom=1", "")
|
||||
isbn10 = None
|
||||
isbn13 = None
|
||||
for iid in (
|
||||
|
|
Loading…
Add table
Reference in a new issue