fix: 固定文本换行为 LF,黄豆登录可选播放线路
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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 "", ""
|
||||
|
||||
Reference in New Issue
Block a user