Files
RaptDramaDump/server/services/dramabox/downloads.py
T
Nixevol cea741eead feat: DramaBox 全量走 App 接口,清单可停止并避免卡死
分类按 App 翻页,精选走推荐接口。清单顶部显示进度,停止后不再拉新剧,已拿到的封面继续加载。列表只绘制可见卡片,避免大量剧目占满主线程。
2026-10-24 03:03:27 +08:00

68 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pathlib import Path
from server.services.downloads import DownloadManager, _plain_text
from server.services.dramabox.app_api import book_brief
from server.services.dramabox.client import USER_AGENT, client
from server.services.dramabox.covers import covers
from server.services.dramabox.private_mp4 import decrypt_file_if_needed
from server.services.dramabox import playlist as db_playlist
ROOT = Path(__file__).resolve().parents[3]
def _load_episodes(_token, _device, drama_id: str, locale: str = "") -> list[dict]:
return db_playlist.load_episodes(str(drama_id), locale or client.language)
def _write_intro(folder: Path, drama_id: str, title: str, _token: str, _device) -> None:
name = title.strip()
desc = ""
language = client.language
country = ""
tags = ""
count = ""
try:
detail = book_brief(str(drama_id))
fetched = detail.get("name") or ""
if fetched:
name = fetched
desc = _plain_text(detail.get("introduction") or "")
tags = detail.get("tags") or ""
count = detail.get("count") or ""
profile = client.profile or {}
country = str(profile.get("country") or "")
except Exception:
pass
lines = [
f"ID: {drama_id}",
f"名称: {name}",
f"简介: {desc}",
f"地区: {country or '—'}",
f"语言: {language or '—'}",
f"分类: {tags or '—'}",
f"集数: {count or '—'}",
"",
]
(folder / "简介.txt").write_text("\n".join(lines), encoding="utf-8")
def _read_cover(image: str):
digest = (image or "").rstrip("/").rsplit("/", 1)[-1].strip()
return covers.read(digest)
def _auth():
return client.token, None
downloads = DownloadManager(
state_dir=ROOT / "cache" / "dramabox" / "downloads",
default_directory=str((Path.cwd() / "download" / "dramabox").resolve()),
load_episodes=_load_episodes,
write_intro=_write_intro,
read_cover=_read_cover,
current_auth=_auth,
headers={"User-Agent": USER_AGENT, "Referer": "https://www.dramaboxapp.com/", "Origin": "https://www.dramaboxapp.com"},
prepare_file=decrypt_file_if_needed,
)