fix: ValueError: Decompressed Data Too Large

This commit is contained in:
mungai-njoroge 2023-10-21 19:32:35 +03:00
parent 574ccf9fea
commit f3faea610e
3 changed files with 15 additions and 15 deletions

View File

@ -5,7 +5,7 @@ from io import BytesIO
from pathlib import Path
import requests
from PIL import Image, UnidentifiedImageError
from PIL import Image, PngImagePlugin, UnidentifiedImageError
from requests.exceptions import ConnectionError as RequestConnectionError
from requests.exceptions import ReadTimeout
@ -15,9 +15,12 @@ from app.store import artists as artist_store
from app.utils.hashing import create_hash
from app.utils.progressbar import tqdm
CHECK_ARTIST_IMAGES_KEY = ""
LARGE_ENOUGH_NUMBER = 100
PngImagePlugin.MAX_TEXT_CHUNK = LARGE_ENOUGH_NUMBER * (1024**2)
# https://stackoverflow.com/a/61466412
def get_artist_image_link(artist: str):
"""
@ -36,7 +39,7 @@ def get_artist_image_link(artist: str):
artist_hash = create_hash(artist, decode=True)
if res_hash == artist_hash:
return res["picture_big"]
return str(res["picture_big"]).removesuffix(".jpg") + ".png"
return None
except (RequestConnectionError, ReadTimeout, IndexError, KeyError):

View File

@ -263,18 +263,16 @@ class ProcessTrackThumbnails:
# process the rest
key_album_map = ((instance_key, album) for album in albums)
# with ThreadPoolExecutor(max_workers=CPU_COUNT) as executor:
# results = list(
# tqdm(
# executor.map(get_image, key_album_map),
# total=len(albums),
# desc="Extracting track images",
# )
# )
with ThreadPoolExecutor(max_workers=CPU_COUNT) as executor:
results = list(
tqdm(
executor.map(get_image, key_album_map),
total=len(albums),
desc="Extracting track images",
)
)
# list(results)
for album in key_album_map:
get_image(album)
list(results)
def save_similar_artists(_map: tuple[str, Artist]):

View File

@ -56,7 +56,6 @@ def extract_thumb(filepath: str, webp_path: str, overwrite=False) -> bool:
album_art = parse_album_art(filepath)
if album_art is not None:
print("Reading image: " + filepath)
try:
img = Image.open(BytesIO(album_art))
except (UnidentifiedImageError, OSError):