style: 统一 Ruff 代码格式

This commit is contained in:
yml2213
2026-08-30 21:04:52 +08:00
parent c891ac982e
commit 47e19ed7b2
90 changed files with 5574 additions and 2350 deletions
+29 -13
View File
@@ -26,6 +26,7 @@
python -m core.huya.account_env <账号> <密码> --new-device # 抛弃旧环境, 换新设备
python -m core.huya.account_env <账号> --show # 只查看该账号绑定
"""
from __future__ import annotations
import hashlib
@@ -35,10 +36,10 @@ import sys
import time
from .device_profile import (
HDID32, # 登录帧 t1.t0 32hex 常量 (R15 公式结果, k1 来源见 R39; device_profile.py)
HDID32, # 登录帧 t1.t0 32hex 常量 (R15 公式结果, k1 来源见 R39; device_profile.py)
_load_db,
_save_db,
get_profile, # 幂等画像: 同账号永远复用同一套 (data/huya_device_profiles.json)
get_profile, # 幂等画像: 同账号永远复用同一套 (data/huya_device_profiles.json)
)
from .app_login import HuyaAppPasswordLogin
@@ -77,7 +78,9 @@ def get_or_create_env(account: str, force_new: bool = False) -> dict:
record["guid32"] = _rand_hex(16, b"guid")
changed = True
if "hebe" not in record:
record["hebe"] = {f"Hebe_D{i}": _rand_hex(16, f"hebe{i}".encode()) for i in range(1, 6)}
record["hebe"] = {
f"Hebe_D{i}": _rand_hex(16, f"hebe{i}".encode()) for i in range(1, 6)
}
changed = True
if changed:
db[account] = record
@@ -88,8 +91,12 @@ def get_or_create_env(account: str, force_new: bool = False) -> dict:
# ---------------------------------------------------------------------------
# 绑定 + 登录: 主流程
# ---------------------------------------------------------------------------
def bind_and_login(account: str, password: str,
force_new_device: bool = False, proxies: dict | None = None) -> dict:
def bind_and_login(
account: str,
password: str,
force_new_device: bool = False,
proxies: dict | None = None,
) -> dict:
"""账号 ↔ 环境绑定并登录。
注册链在 login_cred_with_flow 内部执行一次 (register_device 用的 fingerprint
@@ -97,9 +104,11 @@ def bind_and_login(account: str, password: str,
沿用同一组设备字段 (app_login.login_cred_with_flow)。
"""
env = get_or_create_env(account, force_new=force_new_device)
print(f"[env] {account}{env.get('vendor')}/{env.get('model')} "
f"fp40={env.get('fingerprint', '')[:12]}... guid32={env.get('guid32', '')[:12]}... "
f"t1.t0={env.get('hdid', '')[:12]}...")
print(
f"[env] {account}{env.get('vendor')}/{env.get('model')} "
f"fp40={env.get('fingerprint', '')[:12]}... guid32={env.get('guid32', '')[:12]}... "
f"t1.t0={env.get('hdid', '')[:12]}..."
)
# device_info 显式传入本环境 (否则 HuyaAppPasswordLogin 内部会再走一次
# get_profile —— 结果相同, 但显式传入让"环境→注册→登录"的数据流向可读);
@@ -108,13 +117,16 @@ def bind_and_login(account: str, password: str,
login_env.setdefault("device_id", env.get("device_id"))
result = HuyaAppPasswordLogin(
account, password, proxies=proxies, device_info=login_env,
account,
password,
proxies=proxies,
device_info=login_env,
).login()
# ---- 绑定元数据回写 (令牌不入库: t2/t5 每次登录实时签发, 环境才是长期身份) ----
db = _load_db()
record = dict(db.get(account) or env)
record.setdefault("bound_at", int(time.time())) # 首次绑定时间
record.setdefault("bound_at", int(time.time())) # 首次绑定时间
record["last_login"] = {
"ok": result.success,
"msg": result.message[:120],
@@ -125,9 +137,13 @@ def bind_and_login(account: str, password: str,
return {
"account": account,
"env": {"model": env.get("model"), "vendor": env.get("vendor"),
"fingerprint": env.get("fingerprint"), "guid32": env.get("guid32"),
"hdid_t1t0": env.get("hdid")},
"env": {
"model": env.get("model"),
"vendor": env.get("vendor"),
"fingerprint": env.get("fingerprint"),
"guid32": env.get("guid32"),
"hdid_t1t0": env.get("hdid"),
},
"login_success": result.success,
"login_message": result.message,
"code": getattr(result, "code", None),