feat: 将工具更名为 VideosDownTools,并完善黄豆登录与清单

This commit is contained in:
Nixevol
2026-10-25 01:58:29 +08:00
parent 7253217e18
commit 3c2105c786
27 changed files with 1349 additions and 237 deletions
+89 -6
View File
@@ -11,10 +11,12 @@ from server.services.http import http
from server.services.huangdou import catalog as hd_catalog
from server.services.huangdou import login as hd_login
from server.services.huangdou import playlist as hd_playlist
from server.services.huangdou import accounts as hd_accounts
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.downloads import downloads as hd_downloads
from server.services.huangdou.downloads import enqueue_download
from server.services.playlist import is_direct_media
router = APIRouter(prefix="/api/huangdou")
@@ -24,6 +26,37 @@ class TokenBody(BaseModel):
token: str = ""
refresh: bool = False
keyword: str = ""
host: str = ""
class FingerprintBody(BaseModel):
browserName: str = ""
language: str = ""
userAgent: str = ""
platform: str = ""
class SavedAccountBody(BaseModel):
username: str = ""
password: str = ""
nickname: str = ""
class SavedAccountsBody(BaseModel):
accounts: list[SavedAccountBody] = []
class LoginBody(BaseModel):
host: str = ""
username: str = ""
password: str = ""
class AccountBody(BaseModel):
token: str = ""
username: str = ""
password: str = ""
rotate_fingerprint: bool = False
class DownloadItem(BaseModel):
@@ -34,6 +67,7 @@ class DownloadItem(BaseModel):
class DownloadStartBody(BaseModel):
token: str = ""
download_points: bool = False
items: list[DownloadItem] = []
@@ -59,9 +93,52 @@ def _require_token(token: str) -> None:
client.token = token
@router.post("/fingerprint")
def adopt_fingerprint(body: FingerprintBody):
client.adopt_browser_fingerprint(body.model_dump())
return {"ok": True}
@router.post("/fingerprint/roll")
def roll_fingerprint():
client.roll_account_fingerprint()
return {"ok": True}
@router.get("/accounts")
def list_accounts():
return {"accounts": hd_accounts.load()}
@router.put("/accounts")
def save_accounts(body: SavedAccountsBody):
return {"accounts": hd_accounts.replace([item.model_dump() for item in body.accounts])}
@router.post("/login")
def login(body: LoginBody):
def action():
entered = hd_login.enter(body.host)
if body.username.strip() and body.password:
return hd_login.login_account(body.username, body.password)
return entered
return call(action)
@router.post("/login/device")
def login_device():
return call(hd_login.enter)
def login_device(body: TokenBody | None = None):
host = body.host if body else ""
return call(lambda: hd_login.enter(host))
@router.post("/login/account")
def login_account(body: AccountBody):
def action():
_require_token(body.token)
return hd_login.login_account(body.username, body.password, body.rotate_fingerprint)
return call(action)
@router.post("/resume")
@@ -131,7 +208,8 @@ def list_episodes(body: PlayBody):
"cid": ep["cid"],
"idx": ep["idx"],
"title": ep["title"],
"playable": bool(ep.get("src")),
"playable": bool(ep.get("playable")),
"points": int(ep.get("points") or 0),
"type": ep.get("type") or "",
"media": "file" if (ep.get("src_kind") == "file" or is_direct_media(ep.get("src") or "")) else "hls",
"is_preview": bool(ep.get("is_preview")),
@@ -156,7 +234,7 @@ def _public_url(url: str) -> str:
def play_segment(url: str):
target = _public_url(url)
try:
upstream = http.open_stream(target, headers={"User-Agent": USER_AGENT, "Referer": "https://pmihlvee.cc/"})
upstream = http.open_stream(target, headers={"User-Agent": USER_AGENT, "Referer": client.host.rstrip("/") + "/"})
except (httpx.HTTPError, TimeoutError, OSError, RuntimeError) as exc:
raise HTTPException(status_code=502, detail="分片读取失败") from exc
media = upstream.headers.get("content-type", "video/mp2t").split(";", 1)[0].strip() or "video/mp2t"
@@ -179,7 +257,7 @@ def play_file(vid: str, cid: int):
if not src:
raise HTTPException(status_code=404, detail=row.get("locked_reason") or "这一集还没有可播放的地址")
try:
upstream = http.open_stream(src, headers={"User-Agent": USER_AGENT, "Referer": "https://pmihlvee.cc/"})
upstream = http.open_stream(src, headers={"User-Agent": USER_AGENT, "Referer": client.host.rstrip("/") + "/"})
except (httpx.HTTPError, TimeoutError, OSError, RuntimeError) as exc:
raise HTTPException(status_code=502, detail="分片读取失败") from exc
media = upstream.headers.get("content-type", "video/mp4").split(";", 1)[0].strip() or "video/mp4"
@@ -236,7 +314,12 @@ def list_downloads():
def start_downloads(body: DownloadStartBody):
def action():
_require_token(body.token)
return hd_downloads.enqueue(body.token, None, [item.model_dump() for item in body.items])
hd_downloads._headers["Referer"] = client.host.rstrip("/") + "/"
return enqueue_download(
body.token,
[item.model_dump() for item in body.items],
body.download_points,
)
return call(action)