rewrite downlaod_post_image function

this now uses the proper functions instead of handling with strings
This commit is contained in:
Marcel Hellwig
2026-01-04 14:43:32 +01:00
parent 593e1828cc
commit 9ff2dc4b92

View File

@@ -1,3 +1,4 @@
from pathlib import Path
from uuid import UUID
from PIL import Image
@@ -11,16 +12,16 @@ def get_year_from_date(first_air_date: str | None) -> int | None:
return None
def download_poster_image(storage_path=None, poster_url=None, id: UUID = None) -> bool:
def download_poster_image(storage_path: Path, poster_url: str, id: UUID) -> bool:
res = requests.get(poster_url, stream=True)
if res.status_code == 200:
image_file_path = storage_path.joinpath(str(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)
if res.status_code == 200:
image_file_path = storage_path.joinpath(str(id)).with_suffix("jpg")
image_file_path.write_bytes(res.content)
original_image = Image.open(image_file_path)
original_image.save(image_file_path.with_suffix(".avif"), quality=50)
original_image.save(image_file_path.with_suffix(".webp"), quality=50)
return True
else:
return False