增加斗鱼账号检测功能

This commit is contained in:
yml2213
2026-07-09 23:12:39 +08:00
parent 1f16193690
commit cd2d02c86e
16 changed files with 1206 additions and 53 deletions
+35 -7
View File
@@ -23,6 +23,23 @@ def _create_api_strategy(strategy_name: str):
return WgapiLoginAPI()
CHECK_STATUS_MESSAGES = {
"account_cancelled": "账号已注销",
"password_wrong": "账号密码错误",
"account_unverified": "账号未认证",
"account_verified": "账号已认证",
"account_auth_unknown": "账号认证状态未知",
}
CHECK_STATUS_LOG_LEVELS = {
"account_cancelled": "warning",
"password_wrong": "error",
"account_unverified": "warning",
"account_verified": "success",
"account_auth_unknown": "warning",
}
class LoginBatchRunner:
"""批量登录执行器,在线程中运行,通过 ThreadPoolExecutor 并发登录多个账号。"""
@@ -39,6 +56,7 @@ class LoginBatchRunner:
loop: Optional[asyncio.AbstractEventLoop] = None,
concurrency: int = 3,
api_strategy: str = "wgapi",
mode: str = "login",
):
self.db = db
self.account_ids = account_ids
@@ -54,6 +72,7 @@ class LoginBatchRunner:
self.batch_id = uuid.uuid4().hex[:12]
self.concurrency = max(1, min(concurrency, 10)) # 限制 1-10
self.api_strategy = _create_api_strategy(api_strategy)
self.mode = "check" if mode == "check" else "login"
self._stop = threading.Event()
self._counter_lock = threading.Lock()
self._completed = 0
@@ -129,7 +148,8 @@ class LoginBatchRunner:
self._completed += 1
current = self._completed
self._push_log("info", f"[{current}/{total}] 开始登录: {acc_info['username']}")
action_name = "检测" if self.mode == "check" else "登录"
self._push_log("info", f"[{current}/{total}] 开始{action_name}: {acc_info['username']}")
# 解析代理配置
proxy_dict, proxy_msg = self._resolve_static_proxy()
@@ -165,9 +185,16 @@ class LoginBatchRunner:
stop_event=self._stop,
api_strategy=self.api_strategy,
)
result = loginer.login()
result = loginer.check_account() if self.mode == "check" else loginer.login()
if result.success:
if self.mode == "check" and result.success:
status = result.code if result.code in CHECK_STATUS_MESSAGES else "account_auth_unknown"
task.status = status
task.cookie = ""
task.message = result.message or CHECK_STATUS_MESSAGES[status]
level = CHECK_STATUS_LOG_LEVELS.get(status, "info")
self._push_log(level, f"[{current}] {acc_info['username']} 检测结果: {task.message}")
elif result.success:
task.status = "success"
task.cookie = result.cookie
task.message = result.message or "登录成功"
@@ -175,12 +202,12 @@ class LoginBatchRunner:
else:
task.status = "failed"
task.message = result.message
self._push_log("error", f"[{current}] {acc_info['username']} 登录失败: {result.message}")
self._push_log("error", f"[{current}] {acc_info['username']} {action_name}失败: {result.message}")
except Exception as e:
task.status = "error"
task.message = str(e)
self._push_log("error", f"[{current}] {acc_info['username']} 登录异常: {e}")
self._push_log("error", f"[{current}] {acc_info['username']} {action_name}异常: {e}")
task.finished_at = datetime.now(timezone.utc)
worker_db.commit()
@@ -192,7 +219,8 @@ class LoginBatchRunner:
"""在线程中执行批量登录。"""
batch_id = self.batch_id
concurrency = self.concurrency
self._push_log("info", f"批量登录任务 {batch_id} 开始,共 {len(self.account_ids)} 个账号,并发数: {concurrency}")
action_name = "账号检测" if self.mode == "check" else "登录"
self._push_log("info", f"批量{action_name}任务 {batch_id} 开始,共 {len(self.account_ids)} 个账号,并发数: {concurrency}")
# 批次开始前同步一次出口 IP 到白名单,后续 fetch_new_proxy 不再主动同步
if self._shared_proxy_fetcher:
@@ -280,7 +308,7 @@ class LoginBatchRunner:
except Exception as e:
self._push_log("error", f"Worker 异常: {e}")
self._push_log("info", f"批量登录任务 {batch_id} 完成")
self._push_log("info", f"批量{action_name}任务 {batch_id} 完成")
self._push_log("result", "")
finally:
# 确保 DB Session 被关闭,避免连接泄漏