mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-18 14:54:04 +02:00
rewrite downlaod_post_image function
this now uses the proper functions instead of handling with strings
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user