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)
|
||||
|
||||
Reference in New Issue
Block a user