优化 gui 不急
This commit is contained in:
+37
-4
@@ -1,5 +1,6 @@
|
||||
"""登录工作线程模块"""
|
||||
|
||||
import csv
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
@@ -13,6 +14,13 @@ from douyu.email_verifier import get_email_config_for_account
|
||||
|
||||
|
||||
EMAIL_PATTERN = re.compile(r'^[^\s@|]+@[^\s@|]+\.[^\s@|]+$')
|
||||
HEADER_NAMES = {
|
||||
'username', 'user', 'account', '账号', '用户名', '斗鱼账号',
|
||||
'password', 'pass', 'pwd', '密码', '登录密码',
|
||||
'email', 'mail', '邮箱', '邮箱地址',
|
||||
'email_password', 'email_pass', 'email_pwd', 'mail_password',
|
||||
'mail_pass', '邮箱密码', '邮箱授权码', '授权码',
|
||||
}
|
||||
|
||||
|
||||
def get_imap_server(email: str) -> str:
|
||||
@@ -29,6 +37,27 @@ def _is_ascii(value: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _split_account_line(line: str) -> list[str]:
|
||||
"""拆分单行账号数据,支持竖线、Tab和CSV逗号。"""
|
||||
if '|' in line:
|
||||
return line.split('|')
|
||||
if '\t' in line:
|
||||
return line.split('\t')
|
||||
if ',' in line:
|
||||
return next(csv.reader([line]))
|
||||
return line.split()
|
||||
|
||||
|
||||
def _looks_like_header(parts: list[str]) -> bool:
|
||||
"""判断一行是否像表头。"""
|
||||
normalized = {
|
||||
part.strip().lower().replace('-', '_')
|
||||
for part in parts
|
||||
if part.strip()
|
||||
}
|
||||
return len(normalized & HEADER_NAMES) >= 2
|
||||
|
||||
|
||||
def parse_accounts_text(text: str) -> list[Account]:
|
||||
"""
|
||||
解析账号文本
|
||||
@@ -45,7 +74,10 @@ def parse_accounts_text(text: str) -> list[Account]:
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
|
||||
parts = line.split('|')
|
||||
parts = _split_account_line(line)
|
||||
if line_num == 1 and _looks_like_header(parts):
|
||||
continue
|
||||
|
||||
if len(parts) != 4:
|
||||
logger.warning(f"第{line_num}行格式错误,需要4个字段,实际{len(parts)}个: {line}")
|
||||
continue
|
||||
@@ -117,13 +149,14 @@ class LoginWorker(threading.Thread):
|
||||
proxy_api_url = None
|
||||
|
||||
if self.proxy_config and self.proxy_config.enabled:
|
||||
if self.proxy_config.api_url:
|
||||
proxy_api_url = self.proxy_config.api_url
|
||||
elif self.proxy_config.http or self.proxy_config.https:
|
||||
if self.proxy_config.http or self.proxy_config.https:
|
||||
# 优先使用GUI预检通过的代理,避免进入登录流程后再直接获取未验证代理。
|
||||
proxy_url = {
|
||||
'http': self.proxy_config.http or self.proxy_config.https,
|
||||
'https': self.proxy_config.https or self.proxy_config.http,
|
||||
}
|
||||
elif self.proxy_config.api_url:
|
||||
proxy_api_url = self.proxy_config.api_url
|
||||
|
||||
# 创建登录器
|
||||
loginer = DouyuLogin(
|
||||
|
||||
Reference in New Issue
Block a user