feat (ui): toevoegen van banner en series info - afgerond
This commit is contained in:
+52
-14
@@ -107,9 +107,34 @@ def _status_name(value) -> str | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _pick_banner_url(artworks: list[dict]) -> str | None:
|
def _fetch_artwork_type_labels(client: TvdbClient) -> dict[int, str]:
|
||||||
banner_candidates = []
|
payload = client.get("/artwork/types")
|
||||||
fallback_candidates = []
|
items = payload.get("data", []) if isinstance(payload, dict) else []
|
||||||
|
labels: dict[int, str] = {}
|
||||||
|
|
||||||
|
for item in items:
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
continue
|
||||||
|
type_id = item.get("id")
|
||||||
|
try:
|
||||||
|
type_id = int(type_id)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
continue
|
||||||
|
label = (
|
||||||
|
item.get("slug")
|
||||||
|
or item.get("name")
|
||||||
|
or ""
|
||||||
|
)
|
||||||
|
label = label.lower().strip() if isinstance(label, str) else ""
|
||||||
|
labels[type_id] = label
|
||||||
|
|
||||||
|
return labels
|
||||||
|
|
||||||
|
|
||||||
|
def _pick_banner_url(artworks: list[dict], artwork_type_labels: dict[int, str]) -> str | None:
|
||||||
|
strict_banner_candidates = []
|
||||||
|
wide_fallback_candidates = []
|
||||||
|
generic_wide_candidates = []
|
||||||
|
|
||||||
for artwork in artworks:
|
for artwork in artworks:
|
||||||
if not isinstance(artwork, dict):
|
if not isinstance(artwork, dict):
|
||||||
@@ -133,19 +158,31 @@ def _pick_banner_url(artworks: list[dict]) -> str | None:
|
|||||||
|
|
||||||
ratio = (width / height) if width > 0 and height > 0 else 0.0
|
ratio = (width / height) if width > 0 and height > 0 else 0.0
|
||||||
record = (score, width, image.strip())
|
record = (score, width, image.strip())
|
||||||
|
type_label = ""
|
||||||
|
try:
|
||||||
|
artwork_type = int(artwork.get("type"))
|
||||||
|
type_label = artwork_type_labels.get(artwork_type, "")
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
type_label = ""
|
||||||
|
|
||||||
if ratio >= 1.4:
|
if "banner" in type_label:
|
||||||
banner_candidates.append(record)
|
strict_banner_candidates.append(record)
|
||||||
else:
|
elif any(token in type_label for token in ("fanart", "background", "landscape")):
|
||||||
fallback_candidates.append(record)
|
wide_fallback_candidates.append(record)
|
||||||
|
elif ratio >= 1.4:
|
||||||
|
generic_wide_candidates.append(record)
|
||||||
|
|
||||||
if banner_candidates:
|
if strict_banner_candidates:
|
||||||
banner_candidates.sort(key=lambda x: (x[0], x[1]), reverse=True)
|
strict_banner_candidates.sort(key=lambda x: (x[0], x[1]), reverse=True)
|
||||||
return banner_candidates[0][2]
|
return strict_banner_candidates[0][2]
|
||||||
|
|
||||||
if fallback_candidates:
|
if wide_fallback_candidates:
|
||||||
fallback_candidates.sort(key=lambda x: (x[0], x[1]), reverse=True)
|
wide_fallback_candidates.sort(key=lambda x: (x[0], x[1]), reverse=True)
|
||||||
return fallback_candidates[0][2]
|
return wide_fallback_candidates[0][2]
|
||||||
|
|
||||||
|
if generic_wide_candidates:
|
||||||
|
generic_wide_candidates.sort(key=lambda x: (x[0], x[1]), reverse=True)
|
||||||
|
return generic_wide_candidates[0][2]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -162,8 +199,9 @@ def get_series_summary(series_id: int):
|
|||||||
|
|
||||||
artworks = extended_data.get("artworks")
|
artworks = extended_data.get("artworks")
|
||||||
artworks = artworks if isinstance(artworks, list) else []
|
artworks = artworks if isinstance(artworks, list) else []
|
||||||
|
artwork_type_labels = _fetch_artwork_type_labels(client)
|
||||||
|
|
||||||
banner_url = _pick_banner_url(artworks)
|
banner_url = _pick_banner_url(artworks, artwork_type_labels)
|
||||||
poster_url = (
|
poster_url = (
|
||||||
base_data.get("image")
|
base_data.get("image")
|
||||||
or extended_data.get("image")
|
or extended_data.get("image")
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user