Files
MediaManager/media_manager/metadataProvider/utils.py
Marcel Hellwig 5368cad77a ruff: add S linter
this mostly adds a timeout=60 to all requests

this does mainly wants a timeout to all requests functions, since when
left out they hang infinitly.
I added a timeout of 60s, which is probably way too high, but since
before this there was none, I guess it's an improvement?
2026-01-05 19:30:42 +01:00

28 lines
818 B
Python

from pathlib import Path
from uuid import UUID
import requests
from PIL import Image
def get_year_from_date(first_air_date: str | None) -> int | None:
if first_air_date:
return int(first_air_date.split("-")[0])
else:
return None
def download_poster_image(storage_path: Path, poster_url: str, id: UUID) -> bool:
res = requests.get(poster_url, stream=True, timeout=60)
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