77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
from pathlib import Path
|
||
|
||
from server.services.downloads import DownloadManager, _plain_text
|
||
from server.services.huangdou import api
|
||
from server.services.huangdou.client import client
|
||
from server.services.huangdou.covers import covers
|
||
from server.services.huangdou.crypto import USER_AGENT
|
||
from server.services.huangdou import playlist as hd_playlist
|
||
|
||
ROOT = Path(__file__).resolve().parents[3]
|
||
|
||
|
||
def _load_episodes(_token, _device, drama_id: str) -> list[dict]:
|
||
return hd_playlist.load_episodes(str(drama_id))
|
||
|
||
|
||
def _write_intro(folder: Path, drama_id: str, title: str, _token: str, _device) -> None:
|
||
name = title.strip()
|
||
desc = ""
|
||
pay_type = ""
|
||
free_episodes = ""
|
||
vip_episodes = ""
|
||
points_price = ""
|
||
money = ""
|
||
try:
|
||
detail = api.drama_detail(str(drama_id))
|
||
fetched = str(detail.get("name") or "").strip()
|
||
if fetched:
|
||
name = fetched
|
||
desc = _plain_text(detail.get("description") or "")
|
||
pay_type = _field(detail.get("pay_type"))
|
||
free_episodes = _field(detail.get("free_episodes"))
|
||
vip_episodes = _field(detail.get("vip_episodes"))
|
||
points_price = _field(detail.get("points_price"))
|
||
money = _field(detail.get("money"))
|
||
except Exception:
|
||
pass
|
||
lines = [
|
||
f"ID: {drama_id}",
|
||
f"名称: {name}",
|
||
f"简介: {desc}",
|
||
f"付费类型: {pay_type or '—'}",
|
||
f"免费集数: {free_episodes or '—'}",
|
||
f"VIP 集: {vip_episodes or '—'}",
|
||
f"积分价格: {points_price or '—'}",
|
||
f"金额: {money 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 _field(value) -> str:
|
||
if isinstance(value, list):
|
||
return "、".join(str(item) for item in value if item not in (None, ""))
|
||
text = str(value or "").strip()
|
||
return text
|
||
|
||
|
||
def _auth():
|
||
return client.token, None
|
||
|
||
|
||
downloads = DownloadManager(
|
||
state_dir=ROOT / "cache" / "huangdou" / "downloads",
|
||
default_directory=str((Path.cwd() / "download" / "huangdou").resolve()),
|
||
load_episodes=_load_episodes,
|
||
write_intro=_write_intro,
|
||
read_cover=_read_cover,
|
||
current_auth=_auth,
|
||
headers={"User-Agent": USER_AGENT, "Referer": "https://pmihlvee.cc/"},
|
||
)
|