feat: 补全短剧全量清单并接入 DramaBox 官网登录

This commit is contained in:
Nixevol
2026-10-22 02:20:16 +08:00
parent 39774ad9cc
commit 00e78661a7
22 changed files with 894 additions and 194 deletions
+13 -12
View File
@@ -11,15 +11,16 @@ from server.services.playlist import is_direct_media, looks_like_segment
CACHE_DIR = Path(__file__).resolve().parents[3] / "cache" / "dramabox" / "playlists"
def load_episodes(drama_id: str) -> list[dict]:
def load_episodes(drama_id: str, language: str = "") -> list[dict]:
drama_id = str(drama_id or "").strip()
language = (language or client.language).strip()
if not drama_id:
raise RuntimeError("没有这部剧")
cached = _read_cache(drama_id)
fresh = _fetch_episodes(drama_id)
cached = _read_cache(drama_id, language)
fresh = _fetch_episodes(drama_id, language)
merged, save = _merge(cached, fresh)
if save or (not cached and merged):
_write_cache(drama_id, merged)
_write_cache(drama_id, language, merged)
return merged
@@ -47,8 +48,8 @@ def playback_playlist(src: str, drama_id: str = "") -> str:
return _rewrite_playlist(http.read_text(variant_url, headers=headers), variant_url)
def _fetch_episodes(drama_id: str) -> list[dict]:
data = api.film(drama_id)
def _fetch_episodes(drama_id: str, language: str = "") -> list[dict]:
data = api.film(drama_id, language or None)
rows = data.get("chapterList") if isinstance(data, dict) else None
if not isinstance(rows, list) or not rows:
raise RuntimeError("没有读到分集")
@@ -123,12 +124,12 @@ def _merge(cached: list[dict], fresh: list[dict]) -> tuple[list[dict], bool]:
return merged, filled_fresh >= filled_cached and filled_fresh > 0
def _cache_file(drama_id: str) -> Path:
return CACHE_DIR / client.language / f"{drama_id}.json"
def _cache_file(drama_id: str, language: str = "") -> Path:
return CACHE_DIR / (language or client.language) / f"{drama_id}.json"
def _read_cache(drama_id: str) -> list[dict]:
path = _cache_file(drama_id)
def _read_cache(drama_id: str, language: str = "") -> list[dict]:
path = _cache_file(drama_id, language)
if not path.is_file():
return []
try:
@@ -139,8 +140,8 @@ def _read_cache(drama_id: str) -> list[dict]:
return [row for row in rows if isinstance(row, dict)] if isinstance(rows, list) else []
def _write_cache(drama_id: str, episodes: list[dict]) -> None:
path = _cache_file(drama_id)
def _write_cache(drama_id: str, language: str, episodes: list[dict]) -> None:
path = _cache_file(drama_id, language)
path.parent.mkdir(parents=True, exist_ok=True)
temporary = path.with_suffix(".json.tmp")
temporary.write_text(json.dumps({"episodes": episodes}, ensure_ascii=False), encoding="utf-8")