add logic to convert images to avif and webp

This commit is contained in:
maxDorninger
2025-06-08 21:32:59 +02:00
parent 61ecf73f30
commit ec2493afdb
6 changed files with 91 additions and 26 deletions

View File

@@ -1,8 +1,7 @@
import mimetypes
from PIL import Image
import pillow_avif
import requests
def get_year_from_first_air_date(first_air_date: str | None) -> int | None:
if first_air_date:
return int(first_air_date.split("-")[0])
@@ -12,11 +11,14 @@ def get_year_from_first_air_date(first_air_date: str | None) -> int | None:
def download_poster_image(storage_path=None, poster_url=None, show=None) -> bool:
res = requests.get(poster_url, stream=True)
content_type = res.headers["content-type"]
file_extension = mimetypes.guess_extension(content_type)
if res.status_code == 200:
with open(storage_path.joinpath(str(show.id) + file_extension), "wb") as f:
image_file_path = storage_path.joinpath(str(show.id))
with open( str(image_file_path)+".jpg", "wb") as f:
f.write(res.content)
original_image = Image.open(str(image_file_path)+".jpg")
original_image.save(str(image_file_path)+".avif", quality=50)
original_image.save(str(image_file_path)+".webp", quality=50)
return True
else:
return False