fix: 黄豆按站点方式保持登录并自动切换播放线路
This commit is contained in:
@@ -39,6 +39,9 @@ def login_device(*, force_new: bool = False) -> dict:
|
||||
if not token:
|
||||
raise RuntimeError("设备登录没有返回 token")
|
||||
client.token = token
|
||||
remember_login_user(data, account=False)
|
||||
client._renew_blocked.discard("guest")
|
||||
client.save()
|
||||
return data
|
||||
|
||||
|
||||
@@ -64,16 +67,44 @@ def login_username(username: str, password: str, channel_code: str = "") -> dict
|
||||
raise RuntimeError("账号登录没有返回 token")
|
||||
client.account_token = token
|
||||
client.account_username = username.strip()
|
||||
remember_login_user(data, account=True)
|
||||
client._renew_blocked.discard("account")
|
||||
client.save()
|
||||
return data
|
||||
|
||||
|
||||
def user_info(*, identity: str = "guest") -> dict:
|
||||
data = client.request("/user/info", {}, auth=True, identity=identity)
|
||||
return data if isinstance(data, dict) else {}
|
||||
if not isinstance(data, dict):
|
||||
return {}
|
||||
uid = str(data.get("user_id") or data.get("id") or "").strip()
|
||||
if uid:
|
||||
if identity == "account":
|
||||
client.account_user_id = uid
|
||||
else:
|
||||
client.user_id = uid
|
||||
client.save()
|
||||
return data
|
||||
|
||||
|
||||
def system_info() -> dict:
|
||||
def remember_login_user(data: dict, *, account: bool) -> None:
|
||||
uid = ""
|
||||
if isinstance(data, dict):
|
||||
uid = str(data.get("user_id") or data.get("id") or "").strip()
|
||||
for key in ("user", "userInfo", "user_info", "info"):
|
||||
nested = data.get(key)
|
||||
if isinstance(nested, dict) and not uid:
|
||||
uid = str(nested.get("user_id") or nested.get("id") or "").strip()
|
||||
if not uid:
|
||||
return
|
||||
if account:
|
||||
client.account_user_id = uid
|
||||
else:
|
||||
client.user_id = uid
|
||||
|
||||
|
||||
def system_info(*, identity: str = "") -> dict:
|
||||
chosen = identity or ("account" if client.account_token else "guest")
|
||||
data = client.request(
|
||||
"/system/info",
|
||||
{
|
||||
@@ -81,14 +112,43 @@ def system_info() -> dict:
|
||||
"channel_code": "",
|
||||
"share_code": "",
|
||||
"clipboard_text": "",
|
||||
"device_info": device_info(),
|
||||
"package_name": "",
|
||||
"device_info": device_info(chosen),
|
||||
"package_name": "dfa03",
|
||||
},
|
||||
auth=True,
|
||||
identity=chosen,
|
||||
)
|
||||
return data if isinstance(data, dict) else {}
|
||||
|
||||
|
||||
def remember_api_lines(info: dict | None = None) -> list[str]:
|
||||
if info is None:
|
||||
identities = ["account", "guest"] if client.account_token else ["guest"]
|
||||
info = {}
|
||||
for name in identities:
|
||||
try:
|
||||
info = system_info(identity=name)
|
||||
break
|
||||
except TokenExpired:
|
||||
continue
|
||||
except RuntimeError:
|
||||
return list(client.api_lines)
|
||||
else:
|
||||
return list(client.api_lines)
|
||||
if not isinstance(info, dict) or "api_lines" not in info:
|
||||
return list(client.api_lines)
|
||||
hosts = []
|
||||
for item in info.get("api_lines") or []:
|
||||
if not isinstance(item, str) or not item.startswith("https://"):
|
||||
continue
|
||||
host = item.rstrip("/")
|
||||
if host not in hosts:
|
||||
hosts.append(host)
|
||||
client.api_lines = hosts
|
||||
client.save()
|
||||
return hosts
|
||||
|
||||
|
||||
def nav_list() -> list[dict]:
|
||||
data = client.request("/drama/navList", {"with_filters": "1"}, auth=True)
|
||||
rows = _list_of(data)
|
||||
|
||||
@@ -34,6 +34,36 @@ class TokenExpired(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def _connection_error(exc: BaseException) -> bool:
|
||||
text = str(exc).lower()
|
||||
return any(
|
||||
word in text
|
||||
for word in (
|
||||
"ssl",
|
||||
"unexpected_eof",
|
||||
"connection",
|
||||
"timed out",
|
||||
"timeout",
|
||||
"10054",
|
||||
"10060",
|
||||
"连接",
|
||||
"重置",
|
||||
"强迫关闭",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def present_token(token: str, user_id: str) -> str:
|
||||
token = (token or "").strip()
|
||||
user_id = (user_id or "").strip()
|
||||
if not token or not user_id:
|
||||
return token
|
||||
suffix = f"_{user_id}"
|
||||
if token.endswith(suffix):
|
||||
return token
|
||||
return token + suffix
|
||||
|
||||
|
||||
class ApiError(RuntimeError):
|
||||
def __init__(self, message: str, code=None) -> None:
|
||||
super().__init__(message)
|
||||
@@ -50,9 +80,16 @@ class HuangdouClient:
|
||||
self.guest_session_id = ""
|
||||
self.guest_device_info: dict = {}
|
||||
self.token = ""
|
||||
self.user_id = ""
|
||||
self.account_token = ""
|
||||
self.account_user_id = ""
|
||||
self.account_username = ""
|
||||
self.renew_account = None
|
||||
self.renew_guest = None
|
||||
self._renewing = False
|
||||
self._renew_blocked: set[str] = set()
|
||||
self.play_line = ""
|
||||
self.api_lines: list[str] = []
|
||||
self.host = DEFAULT_HOST
|
||||
self.profile: dict = {}
|
||||
self._load()
|
||||
@@ -79,9 +116,14 @@ class HuangdouClient:
|
||||
if isinstance(guest_info, dict) and guest_info:
|
||||
self.guest_device_info = dict(guest_info)
|
||||
self.token = str(data.get("token") or "")
|
||||
self.user_id = str(data.get("user_id") or "")
|
||||
self.account_token = str(data.get("account_token") or "")
|
||||
self.account_user_id = str(data.get("account_user_id") or "")
|
||||
self.account_username = str(data.get("account_username") or "")
|
||||
self.play_line = str(data.get("play_line") or "")
|
||||
lines = data.get("api_lines")
|
||||
if isinstance(lines, list):
|
||||
self.api_lines = [str(item).rstrip("/") for item in lines if str(item).startswith("https://")]
|
||||
host = str(data.get("host") or "")
|
||||
if host.startswith("http://") or host.startswith("https://"):
|
||||
self.host = host.rstrip("/")
|
||||
@@ -100,9 +142,12 @@ class HuangdouClient:
|
||||
"guest_session_id": self.guest_session_id,
|
||||
"guest_device_info": self.guest_device_info,
|
||||
"token": self.token,
|
||||
"user_id": self.user_id,
|
||||
"account_token": self.account_token,
|
||||
"account_user_id": self.account_user_id,
|
||||
"account_username": self.account_username,
|
||||
"play_line": self.play_line,
|
||||
"api_lines": self.api_lines,
|
||||
"host": self.host,
|
||||
"profile": self.profile,
|
||||
}
|
||||
@@ -150,6 +195,7 @@ class HuangdouClient:
|
||||
self.guest_session_id = session_id_of("")
|
||||
self.guest_device_info = self._new_device_info()
|
||||
self.token = ""
|
||||
self.user_id = ""
|
||||
self.save()
|
||||
|
||||
def roll_account_fingerprint(self) -> None:
|
||||
@@ -160,6 +206,7 @@ class HuangdouClient:
|
||||
self.device_info = info
|
||||
self.device_info_source = "fixed"
|
||||
self.account_token = ""
|
||||
self.account_user_id = ""
|
||||
self.save()
|
||||
|
||||
def clear_token(self) -> None:
|
||||
@@ -168,7 +215,9 @@ class HuangdouClient:
|
||||
self.guest_session_id = ""
|
||||
self.guest_device_info = {}
|
||||
self.account_token = ""
|
||||
self.account_user_id = ""
|
||||
self.account_username = ""
|
||||
self.user_id = ""
|
||||
self.profile = {}
|
||||
self.save()
|
||||
|
||||
@@ -180,26 +229,71 @@ class HuangdouClient:
|
||||
return self.host
|
||||
|
||||
def request(self, path: str, data: dict | None = None, *, auth: bool = True, identity: str = "guest") -> dict | list | None:
|
||||
try:
|
||||
return self._dispatch(path, data, auth=auth, identity=identity)
|
||||
except TokenExpired:
|
||||
if not auth or self._renewing or identity in self._renew_blocked:
|
||||
raise
|
||||
self._renewing = True
|
||||
try:
|
||||
renew = self.renew_account if identity == "account" else self.renew_guest
|
||||
renewed = bool(renew and renew())
|
||||
finally:
|
||||
self._renewing = False
|
||||
if not renewed:
|
||||
self._renew_blocked.add(identity)
|
||||
raise
|
||||
self._renew_blocked.discard(identity)
|
||||
return self._dispatch(path, data, auth=auth, identity=identity)
|
||||
|
||||
def _dispatch(self, path: str, data: dict | None, *, auth: bool, identity: str) -> dict | list | None:
|
||||
token, device_id, session_id, info = self._identity(identity, auth)
|
||||
user_agent = str((info or {}).get("userAgent") or USER_AGENT)
|
||||
last_error: Exception | None = None
|
||||
for _ in range(2):
|
||||
try:
|
||||
return self._call(
|
||||
self.host,
|
||||
path,
|
||||
data or {},
|
||||
token=token,
|
||||
device_id=device_id,
|
||||
session_id=session_id,
|
||||
user_agent=user_agent,
|
||||
)
|
||||
except (TokenExpired, ApiError):
|
||||
raise
|
||||
except RuntimeError as exc:
|
||||
last_error = exc
|
||||
hosts = [self.host] if token else self._request_hosts()
|
||||
for host in hosts:
|
||||
for _ in range(2):
|
||||
try:
|
||||
payload = self._call(
|
||||
host,
|
||||
path,
|
||||
data or {},
|
||||
token=self._presented_token(token, identity) if auth else "",
|
||||
device_id=device_id,
|
||||
session_id=session_id,
|
||||
user_agent=user_agent,
|
||||
)
|
||||
if host != self.host:
|
||||
self.host = host
|
||||
self.save()
|
||||
return payload
|
||||
except (TokenExpired, ApiError):
|
||||
raise
|
||||
except RuntimeError as exc:
|
||||
last_error = exc
|
||||
if not _connection_error(exc):
|
||||
raise
|
||||
raise last_error or RuntimeError("网络请求异常")
|
||||
|
||||
def _presented_token(self, token: str, identity: str) -> str:
|
||||
if identity == "account":
|
||||
user_id = self.account_user_id
|
||||
if not user_id and self.account_token:
|
||||
profile = self.profile if isinstance(self.profile, dict) else {}
|
||||
if str(profile.get("has_login") or "") == "1":
|
||||
user_id = str(profile.get("id") or "")
|
||||
else:
|
||||
user_id = self.user_id
|
||||
return present_token(token, user_id)
|
||||
|
||||
def _request_hosts(self) -> list[str]:
|
||||
hosts = []
|
||||
for host in [self.host, *self.api_lines]:
|
||||
text = str(host or "").rstrip("/")
|
||||
if text.startswith("https://") and text not in hosts:
|
||||
hosts.append(text)
|
||||
return hosts or [self.host]
|
||||
|
||||
def _identity(self, identity: str, auth: bool) -> tuple[str, str, str, dict]:
|
||||
if identity == "account":
|
||||
self._ensure_fingerprint()
|
||||
@@ -251,6 +345,8 @@ class HuangdouClient:
|
||||
try:
|
||||
response = http.send("POST", url, headers=headers, content=encrypt_body(body, request_id), timeout=30.0)
|
||||
except Exception as exc:
|
||||
if _connection_error(exc):
|
||||
raise RuntimeError("连接中断,请再试一次") from exc
|
||||
raise RuntimeError(f"请求失败: {exc}") from exc
|
||||
if response.status_code != 200:
|
||||
raise RuntimeError(f"网络请求异常 ({response.status_code})")
|
||||
|
||||
@@ -12,7 +12,7 @@ from cryptography.hazmat.primitives.padding import PKCS7
|
||||
WEB_AES_KEY = "7961beb44246e3012ce228d6b5ced05a"
|
||||
IMAGE_AES_KEY = "525202f9149e061d"
|
||||
SIGN_PREFIX = "Dart"
|
||||
APP_VERSION = "2.0.0"
|
||||
APP_VERSION = "1.0.0"
|
||||
DEVICE_TYPE = "web"
|
||||
LANG = "zh-CN"
|
||||
USER_AGENT = (
|
||||
|
||||
@@ -6,8 +6,6 @@ from server.services.huangdou.covers import covers as huangdou_covers
|
||||
def enter(host: str = "") -> dict:
|
||||
if host:
|
||||
client.set_host(host)
|
||||
client.account_token = ""
|
||||
client.account_username = ""
|
||||
client.roll_guest_fingerprint()
|
||||
raw = api.login_device(force_new=False)
|
||||
guest = _user_from_login(raw)
|
||||
@@ -19,6 +17,7 @@ def enter(host: str = "") -> dict:
|
||||
profile = public_profile(None)
|
||||
client.profile = profile
|
||||
client.save()
|
||||
api.remember_api_lines()
|
||||
return {"token": client.token, "profile": profile}
|
||||
|
||||
|
||||
@@ -44,6 +43,7 @@ def login_account(username: str, password: str, rotate_fingerprint: bool = False
|
||||
profile = public_profile(info if isinstance(info, dict) else {})
|
||||
client.profile = profile
|
||||
client.save()
|
||||
api.remember_api_lines()
|
||||
return {"token": client.token, "profile": profile}
|
||||
|
||||
|
||||
@@ -169,6 +169,40 @@ def _truthy(value) -> bool:
|
||||
return text in {"1", "true", "y", "yes", "vip"}
|
||||
|
||||
|
||||
def _renew_account() -> bool:
|
||||
from server.services.huangdou.accounts import load
|
||||
|
||||
username = client.account_username.strip()
|
||||
if not username:
|
||||
return False
|
||||
password = ""
|
||||
for item in load():
|
||||
if item.get("username") == username:
|
||||
password = str(item.get("password") or "")
|
||||
break
|
||||
if not password:
|
||||
return False
|
||||
try:
|
||||
api.login_username(username, password)
|
||||
except Exception:
|
||||
return False
|
||||
return bool(client.account_token)
|
||||
|
||||
|
||||
def _renew_guest() -> bool:
|
||||
if not client.guest_device_id:
|
||||
return False
|
||||
try:
|
||||
api.login_device(force_new=False)
|
||||
except Exception:
|
||||
return False
|
||||
return bool(client.token)
|
||||
|
||||
|
||||
client.renew_account = _renew_account
|
||||
client.renew_guest = _renew_guest
|
||||
|
||||
|
||||
def _number(value) -> int:
|
||||
try:
|
||||
return int(float(str(value or "0")))
|
||||
|
||||
@@ -53,12 +53,13 @@ def episode_src(drama_id: str, cid: int) -> dict:
|
||||
row = _cached_row(drama_id, cid, refresh=True)
|
||||
if not row:
|
||||
return {}
|
||||
if not row.get("playable") or row.get("src"):
|
||||
return row
|
||||
played = _play_rows(drama_id, [dict(row)], allow_buy=False)
|
||||
updated = played[0] if played else row
|
||||
_store_row(drama_id, updated)
|
||||
return updated
|
||||
stale = not row.get("lines_ready")
|
||||
if (row.get("playable") and stale) or row.get("locked_reason") == "登录已失效":
|
||||
played = _play_rows(drama_id, [dict(row)], allow_buy=False)
|
||||
updated = played[0] if played else row
|
||||
_store_row(drama_id, updated)
|
||||
return updated
|
||||
return row
|
||||
|
||||
|
||||
def playback_playlist(src: str) -> str:
|
||||
@@ -102,86 +103,97 @@ def store_fallback_key(source_dir: Path, key: str) -> None:
|
||||
(source_dir / "hls.key").write_bytes(raw)
|
||||
|
||||
|
||||
def line_options(played: dict) -> list[dict]:
|
||||
found = []
|
||||
seen: set[str] = set()
|
||||
def _preview_url(url: str) -> bool:
|
||||
path = (url or "").split("?", 1)[0].lower()
|
||||
return path.endswith("preview.mp4") or "/preview." in path
|
||||
|
||||
|
||||
def _line_urls(played: dict, *, allow_preview: bool) -> list[str]:
|
||||
urls: list[str] = []
|
||||
|
||||
def add(value) -> None:
|
||||
url = str(value or "").strip()
|
||||
if not url or url in urls:
|
||||
return
|
||||
if not allow_preview and _preview_url(url):
|
||||
return
|
||||
urls.append(url)
|
||||
|
||||
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
|
||||
if isinstance(line, dict):
|
||||
add(line.get("url"))
|
||||
add(played.get("m3u8"))
|
||||
if allow_preview:
|
||||
add(played.get("preview_m3u8"))
|
||||
return urls
|
||||
|
||||
|
||||
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):
|
||||
def _open_src(url: str) -> tuple[str, str] | None:
|
||||
if is_direct_media(url):
|
||||
return None if _preview_url(url) else (url, "file")
|
||||
try:
|
||||
if not client.token:
|
||||
api.login_device()
|
||||
return load()
|
||||
except TokenExpired:
|
||||
api.login_device()
|
||||
return load()
|
||||
text = http.read_text(url, headers=_cdn_headers())
|
||||
except Exception:
|
||||
return None
|
||||
if "#EXTM3U" not in text.upper():
|
||||
return None
|
||||
return url, "hls"
|
||||
|
||||
|
||||
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:
|
||||
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:
|
||||
ordered.append(preview)
|
||||
for url in ordered:
|
||||
if url and not is_direct_media(url):
|
||||
urls = _line_urls(played, allow_preview=False) or _line_urls(played, allow_preview=True)
|
||||
for url in urls:
|
||||
if not is_direct_media(url):
|
||||
return url, "hls"
|
||||
for url in ordered:
|
||||
if is_direct_media(url):
|
||||
for url in urls:
|
||||
if is_direct_media(url) and not _preview_url(url):
|
||||
return url, "file"
|
||||
return "", ""
|
||||
|
||||
|
||||
def _ordered_line_urls(played: dict, src: str) -> list[str]:
|
||||
urls = _line_urls(played, allow_preview=False)
|
||||
chosen = (src or "").strip()
|
||||
if chosen and not _preview_url(chosen):
|
||||
urls = [chosen, *[url for url in urls if url != chosen]]
|
||||
return urls
|
||||
|
||||
|
||||
def pick_line(row: dict, line: int) -> str:
|
||||
urls: list[str] = []
|
||||
for item in row.get("line_urls") or []:
|
||||
text = str(item or "").strip()
|
||||
if text and text not in urls and not _preview_url(text):
|
||||
urls.append(text)
|
||||
src = str(row.get("src") or "").strip()
|
||||
if src and not _preview_url(src) and src not in urls:
|
||||
urls.insert(0, src)
|
||||
if line < 0:
|
||||
line = 0
|
||||
if not urls:
|
||||
return src if line == 0 else ""
|
||||
if line >= len(urls):
|
||||
return ""
|
||||
return urls[line]
|
||||
|
||||
|
||||
def _resolve_src(played: dict, *, allow_preview: bool) -> tuple[str, str]:
|
||||
for url in _line_urls(played, allow_preview=False):
|
||||
opened = _open_src(url)
|
||||
if opened:
|
||||
return opened
|
||||
if not allow_preview:
|
||||
return "", ""
|
||||
for url in _line_urls(played, allow_preview=True):
|
||||
if _preview_url(url) and is_direct_media(url):
|
||||
return url, "file"
|
||||
opened = _open_src(url)
|
||||
if opened:
|
||||
return opened
|
||||
return "", ""
|
||||
|
||||
|
||||
def apply_hls_key(text: str, source_dir: Path, key: str) -> str:
|
||||
secret = (key or "").strip()
|
||||
if not secret:
|
||||
@@ -265,6 +277,8 @@ def _skeleton_row(item: dict, *, account_vip: bool) -> dict | None:
|
||||
"duration": _int(item.get("duration")),
|
||||
"methods": item.get("methods") if isinstance(item.get("methods"), list) else [],
|
||||
"is_preview": False,
|
||||
"line_urls": [],
|
||||
"lines_ready": False,
|
||||
"preview_seconds": 0,
|
||||
"preview_m3u8": "",
|
||||
"hls_key": "",
|
||||
@@ -282,6 +296,7 @@ def _play_rows(drama_id: str, skeleton: list[dict], *, allow_buy: bool) -> list[
|
||||
if not allow_buy or not client.account_token:
|
||||
row["src"] = ""
|
||||
row["playable"] = False
|
||||
row["lines_ready"] = True
|
||||
row["locked_reason"] = public_lock_reason(row, row.get("locked_reason") or "")
|
||||
return row
|
||||
try:
|
||||
@@ -289,36 +304,47 @@ def _play_rows(drama_id: str, skeleton: list[dict], *, allow_buy: bool) -> list[
|
||||
except RuntimeError as exc:
|
||||
row["src"] = ""
|
||||
row["playable"] = False
|
||||
row["lines_ready"] = True
|
||||
row["locked_reason"] = public_lock_reason(row, str(exc))
|
||||
return row
|
||||
row["is_buy"] = True
|
||||
row["needs_coin"] = False
|
||||
row["points"] = 0
|
||||
vip_episode = episode_kind(row) in VIP_TYPES
|
||||
identity = "account" if _uses_account(row) else "guest"
|
||||
try:
|
||||
played = api.drama_play(drama_id, int(row["cid"]), identity=identity)
|
||||
except TokenExpired:
|
||||
row["src"] = ""
|
||||
row["playable"] = False
|
||||
row["is_preview"] = False
|
||||
row["lines_ready"] = False
|
||||
row["locked_reason"] = "登录已失效"
|
||||
return row
|
||||
except RuntimeError as exc:
|
||||
row["src"] = ""
|
||||
row["playable"] = False
|
||||
row["lines_ready"] = True
|
||||
row["locked_reason"] = public_lock_reason(row, str(exc))
|
||||
return row
|
||||
preview = str(played.get("preview_m3u8") or "").strip()
|
||||
row["hls_key"] = str(played.get("hls_key") or "").strip()
|
||||
row["is_preview"] = played.get("is_preview") is True
|
||||
row["preview_seconds"] = _int(played.get("preview_seconds"))
|
||||
row["preview_m3u8"] = preview
|
||||
src, kind = _choose_src(played)
|
||||
src, kind = _resolve_src(played, allow_preview=not vip_episode)
|
||||
row["src"] = src
|
||||
row["src_kind"] = kind
|
||||
row["line_urls"] = _ordered_line_urls(played, src)
|
||||
row["lines_ready"] = True
|
||||
if src:
|
||||
row["playable"] = True
|
||||
if kind == "file" or row["is_preview"]:
|
||||
row["is_preview"] = True
|
||||
row["is_preview"] = (not vip_episode) and (kind == "file" and _preview_url(src) or played.get("is_preview") is True and _preview_url(src))
|
||||
row["locked_reason"] = ""
|
||||
row["points"] = 0
|
||||
else:
|
||||
row["playable"] = False
|
||||
row["locked_reason"] = _lock_reason(row)
|
||||
row["is_preview"] = False
|
||||
row["locked_reason"] = _vip_lock_reason(row) if vip_episode else _lock_reason(row)
|
||||
return row
|
||||
|
||||
updated = []
|
||||
@@ -333,6 +359,20 @@ def _play_rows(drama_id: str, skeleton: list[dict], *, allow_buy: bool) -> list[
|
||||
return updated
|
||||
|
||||
|
||||
def _vip_lock_reason(row: dict) -> str:
|
||||
if not client.account_token:
|
||||
return "需要 VIP"
|
||||
try:
|
||||
api.user_info(identity="account")
|
||||
except TokenExpired:
|
||||
client.account_token = ""
|
||||
client.save()
|
||||
return "登录已失效"
|
||||
except RuntimeError:
|
||||
return "这一集暂时不能播放"
|
||||
return "这一集暂时不能播放"
|
||||
|
||||
|
||||
def _uses_account(row: dict) -> bool:
|
||||
if not client.account_token:
|
||||
return False
|
||||
@@ -366,12 +406,14 @@ def _keep_sources(cached: list[dict], fresh: list[dict]) -> list[dict]:
|
||||
merged = []
|
||||
for row in fresh:
|
||||
old = previous.get(int(row["cid"]))
|
||||
if old and old.get("is_preview"):
|
||||
if old and old.get("is_preview") and episode_kind(row) not in VIP_TYPES:
|
||||
row["is_preview"] = True
|
||||
if row.get("playable") and old and old.get("src") and not old.get("is_preview"):
|
||||
row["src"] = old.get("src") or ""
|
||||
row["src_kind"] = old.get("src_kind") or ""
|
||||
row["hls_key"] = old.get("hls_key") or ""
|
||||
row["line_urls"] = old.get("line_urls") or []
|
||||
row["lines_ready"] = bool(old.get("lines_ready"))
|
||||
row["preview_seconds"] = old.get("preview_seconds") or 0
|
||||
row["preview_m3u8"] = old.get("preview_m3u8") or ""
|
||||
merged.append(row)
|
||||
|
||||
Reference in New Issue
Block a user