diff --git a/media_manager/metadataProvider/utils.py b/media_manager/metadataProvider/utils.py index 683bfd7..4e42c10 100644 --- a/media_manager/metadataProvider/utils.py +++ b/media_manager/metadataProvider/utils.py @@ -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