fix: 固定文本换行为 LF,黄豆登录可选播放线路

This commit is contained in:
Nixevol
2026-10-25 02:11:55 +08:00
parent 3c2105c786
commit 3fe936fe70
6 changed files with 174 additions and 14 deletions
+13
View File
@@ -0,0 +1,13 @@
* text=auto eol=lf
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.webp binary
*.ico binary
*.icns binary
*.zip binary
*.exe binary
*.dll binary
*.pyd binary
*.pyc binary
+8
View File
@@ -50,6 +50,7 @@ class LoginBody(BaseModel):
host: str = ""
username: str = ""
password: str = ""
line: str = ""
class AccountBody(BaseModel):
@@ -115,9 +116,16 @@ def save_accounts(body: SavedAccountsBody):
return {"accounts": hd_accounts.replace([item.model_dump() for item in body.accounts])}
@router.post("/lines")
def list_lines(body: TokenBody):
return call(lambda: {"lines": hd_playlist.available_lines(body.host)})
@router.post("/login")
def login(body: LoginBody):
def action():
client.play_line = (body.line or "").strip()
client.save()
entered = hd_login.enter(body.host)
if body.username.strip() and body.password:
return hd_login.login_account(body.username, body.password)
+3
View File
@@ -52,6 +52,7 @@ class HuangdouClient:
self.token = ""
self.account_token = ""
self.account_username = ""
self.play_line = ""
self.host = DEFAULT_HOST
self.profile: dict = {}
self._load()
@@ -80,6 +81,7 @@ class HuangdouClient:
self.token = str(data.get("token") or "")
self.account_token = str(data.get("account_token") or "")
self.account_username = str(data.get("account_username") or "")
self.play_line = str(data.get("play_line") or "")
host = str(data.get("host") or "")
if host.startswith("http://") or host.startswith("https://"):
self.host = host.rstrip("/")
@@ -100,6 +102,7 @@ class HuangdouClient:
"token": self.token,
"account_token": self.account_token,
"account_username": self.account_username,
"play_line": self.play_line,
"host": self.host,
"profile": self.profile,
}
+66 -11
View File
@@ -6,7 +6,7 @@ from pathlib import Path
from urllib.parse import quote, urljoin
from server.services.huangdou import api
from server.services.huangdou.client import client
from server.services.huangdou.client import TokenExpired, client
from server.services.huangdou.coins import (
PAID_TYPES,
VIP_TYPES,
@@ -102,26 +102,81 @@ def store_fallback_key(source_dir: Path, key: str) -> None:
(source_dir / "hls.key").write_bytes(raw)
def _choose_src(played: dict) -> tuple[str, str]:
candidates: list[str] = []
for value in (played.get("m3u8"),):
text = str(value or "").strip()
if text:
candidates.append(text)
def line_options(played: dict) -> list[dict]:
found = []
seen: set[str] = set()
lines = played.get("lines") if isinstance(played.get("lines"), list) else []
for line in lines:
if not isinstance(line, dict):
continue
name = str(line.get("name") or "").strip()
url = str(line.get("url") or "").strip()
if not name or not url or name in seen:
continue
seen.add(name)
found.append({"name": name, "label": name})
return found
def available_lines(host: str = "") -> list[dict]:
if host:
client.set_host(host)
rows = _guest_rows(lambda: api.drama_list(page=1, page_size=3))
last_error = "没有读到线路"
for item in rows:
if not isinstance(item, dict):
continue
drama_id = str(item.get("id") or "").strip()
if not drama_id:
continue
try:
played = _guest_rows(lambda current=drama_id: api.drama_play(current, 1))
except RuntimeError as exc:
last_error = str(exc) or last_error
continue
if not isinstance(played, dict):
continue
lines = line_options(played)
if lines:
return lines
raise RuntimeError(last_error)
def _guest_rows(load):
try:
if not client.token:
api.login_device()
return load()
except TokenExpired:
api.login_device()
return load()
def _choose_src(played: dict) -> tuple[str, str]:
selected = (client.play_line or "").strip()
lines = played.get("lines") if isinstance(played.get("lines"), list) else []
named: list[tuple[str, str]] = []
for line in lines:
if not isinstance(line, dict):
continue
name = str(line.get("name") or "").strip()
url = str(line.get("url") or "").strip()
if url:
candidates.append(url)
named.append((name, url))
ordered = []
if selected:
ordered.extend(url for name, url in named if name == selected)
ordered.extend(url for _name, url in named)
m3u8 = str(played.get("m3u8") or "").strip()
if m3u8:
ordered.append(m3u8)
preview = str(played.get("preview_m3u8") or "").strip()
if preview:
candidates.append(preview)
for url in candidates:
ordered.append(preview)
for url in ordered:
if url and not is_direct_media(url):
return url, "hls"
for url in candidates:
for url in ordered:
if is_direct_media(url):
return url, "file"
return "", ""
+22
View File
@@ -21,6 +21,28 @@ def test_direct_media_and_hls_choice() -> None:
assert kind == "hls"
assert src.endswith("play.m3u8?x=1")
from server.services.huangdou.client import client
client.play_line = "line2"
src, kind = _choose_src({
"m3u8": "https://host.example/play.m3u8?line=free",
"lines": [
{"name": "free", "url": "https://host.example/play.m3u8?line=free"},
{"name": "line2", "url": "https://host.example/play.m3u8?line=line2"},
],
})
assert kind == "hls"
assert "line=line2" in src
client.play_line = ""
src, kind = _choose_src({
"m3u8": "https://host.example/play.m3u8?line=free",
"lines": [
{"name": "free", "url": "https://host.example/play.m3u8?line=free"},
{"name": "line2", "url": "https://host.example/play.m3u8?line=line2"},
],
})
assert "line=free" in src
src, kind = _choose_src({
"m3u8": "",
"preview_m3u8": "https://cdn.example/chapters/2/preview-r10.mp4",
+62 -3
View File
@@ -100,6 +100,7 @@ const ACCOUNTS_KEY = "rapt-accounts";
const PLATFORM_KEY = "rapt-platform";
const DRAMABOX_LANG_KEY = "dramabox-language";
const HUANGDOU_HOST_KEY = "huangdou-host";
const HUANGDOU_LINE_KEY = "huangdou-line";
const HUANGDOU_ACCOUNTS_KEY = "huangdou-accounts";
const HUANGDOU_REMEMBER_KEY = "huangdou-remember";
const DRAMABOX_DEVICE_KEY = "dramabox-device";
@@ -129,6 +130,9 @@ const platformLabel = computed(() => {
});
const dramaboxLang = ref("th");
const huangdouHost = ref(readHuangdouHost());
const huangdouLine = ref(readHuangdouLine());
const huangdouLines = ref<{ name: string; label: string }[]>([]);
const huangdouLinesBusy = ref(false);
const huangdouUser = ref("");
const huangdouPassword = ref("");
const huangdouRemember = ref(readHuangdouRemember());
@@ -263,6 +267,14 @@ function readHuangdouRemember() {
}
}
function readHuangdouLine() {
try {
return localStorage.getItem(HUANGDOU_LINE_KEY) || "";
} catch {
return "";
}
}
function readHuangdouHost() {
try {
const value = localStorage.getItem(HUANGDOU_HOST_KEY) || "";
@@ -292,7 +304,41 @@ function selectPlatform(key: string) {
void loadDramaboxLanguages();
void loadDevices();
}
if (key === "huangdou") void sendHuangdouFingerprint();
if (key === "huangdou") {
void sendHuangdouFingerprint();
void loadHuangdouLines();
}
}
async function loadHuangdouLines() {
huangdouLinesBusy.value = true;
try {
const host = huangdouHost.value.trim() || "https://pmihlvee.cc";
const response = await fetch("/api/huangdou/lines", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ host }),
});
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(typeof payload.detail === "string" ? payload.detail : "没有读到线路");
}
const rows = Array.isArray(payload.lines) ? payload.lines : [];
huangdouLines.value = rows
.map((item: { name?: string; label?: string }) => ({
name: String(item?.name || "").trim(),
label: String(item?.label || item?.name || "").trim(),
}))
.filter((item: { name: string }) => item.name);
if (!huangdouLines.value.some((item) => item.name === huangdouLine.value)) {
huangdouLine.value = huangdouLines.value[0]?.name || "";
}
} catch (exc) {
huangdouLines.value = [];
error.value = exc instanceof Error ? exc.message : "没有读到线路";
} finally {
huangdouLinesBusy.value = false;
}
}
function tokenKey() {
@@ -1016,11 +1062,13 @@ async function loginHuangdou(asGuest = false) {
const host = huangdouHost.value.trim() || "https://pmihlvee.cc";
huangdouHost.value = host;
localStorage.setItem(HUANGDOU_HOST_KEY, host);
localStorage.setItem(HUANGDOU_LINE_KEY, huangdouLine.value);
const response = await fetch("/api/huangdou/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
host,
line: huangdouLine.value,
username: asGuest ? "" : huangdouUser.value.trim(),
password: asGuest ? "" : huangdouPassword.value,
}),
@@ -1315,7 +1363,10 @@ onMounted(async () => {
await loadDramaboxLanguages();
void loadDevices();
}
if (platform.value === "huangdou") void sendHuangdouFingerprint();
if (platform.value === "huangdou") {
void sendHuangdouFingerprint();
void loadHuangdouLines();
}
let saved = readSavedToken();
if (!saved && isolated.value) {
try {
@@ -1533,7 +1584,15 @@ onUnmounted(stopLive);
<n-form label-placement="left" label-width="96" size="small" :show-feedback="false" @submit.prevent="login">
<template v-if="platform === 'huangdou'">
<n-form-item label="域名">
<n-input v-model:value="huangdouHost" placeholder="https://pmihlvee.cc" />
<n-input v-model:value="huangdouHost" placeholder="https://pmihlvee.cc" @blur="loadHuangdouLines" />
</n-form-item>
<n-form-item label="线路">
<n-select
v-model:value="huangdouLine"
:options="huangdouLines.map((item) => ({ label: item.label, value: item.name }))"
:loading="huangdouLinesBusy"
placeholder="选择线路"
/>
</n-form-item>
<n-form-item v-if="huangdouAccounts.length" label="已保存">
<div class="device-line">