mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-19 04:54:11 +02:00
add logic to convert images to avif and webp
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user