api bugfix
This commit is contained in:
@@ -133,24 +133,50 @@ class MangaBakaWorksResolver:
|
||||
# ------------------------------------------------------------------
|
||||
@staticmethod
|
||||
def _pick_cover_url(cover) -> "str | None":
|
||||
"""Selects the best (raw-preferred) cover URL from a cover object."""
|
||||
"""
|
||||
Selects the best cover URL from a MangaBaka cover object.
|
||||
|
||||
Real API shape:
|
||||
"raw": {"url": "...", "size": ..., "height": ..., "width": ...}
|
||||
"x150": {"x1": "...", "x2": "...", "x3": "..."}
|
||||
"x250": {...}
|
||||
"x350": {...}
|
||||
|
||||
Order: raw original > x350@x3 > x250@x3 > x150@x3 ...
|
||||
"""
|
||||
if not cover:
|
||||
return None
|
||||
if isinstance(cover, str):
|
||||
return cover
|
||||
if isinstance(cover, dict):
|
||||
url = cover.get("raw").get("url") or None
|
||||
if url:
|
||||
return url
|
||||
if not isinstance(cover, dict):
|
||||
return None
|
||||
|
||||
# Generic fallback: any HTTP URL in the dict
|
||||
for val in cover.values():
|
||||
if isinstance(val, str) and val.startswith("http"):
|
||||
return val
|
||||
if isinstance(val, dict):
|
||||
for sub_val in val.values():
|
||||
if isinstance(sub_val, str) and sub_val.startswith("http"):
|
||||
return sub_val
|
||||
raw = cover.get("raw")
|
||||
if isinstance(raw, dict):
|
||||
url = raw.get("url")
|
||||
if isinstance(url, str) and url:
|
||||
return url
|
||||
elif isinstance(raw, str) and raw:
|
||||
return raw
|
||||
|
||||
for size_key in ("x350", "x250", "x150"):
|
||||
variant = cover.get(size_key)
|
||||
if isinstance(variant, dict):
|
||||
for density in ("x3", "x2", "x1"):
|
||||
url = variant.get(density)
|
||||
if isinstance(url, str) and url:
|
||||
return url
|
||||
elif isinstance(variant, str) and variant:
|
||||
return variant
|
||||
|
||||
# Last-ditch: any HTTP URL anywhere in the structure
|
||||
for val in cover.values():
|
||||
if isinstance(val, str) and val.startswith("http"):
|
||||
return val
|
||||
if isinstance(val, dict):
|
||||
for sub_val in val.values():
|
||||
if isinstance(sub_val, str) and sub_val.startswith("http"):
|
||||
return sub_val
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user