feat: 优化配置和日志提取逻辑,增强用户体验和数据准确性

This commit is contained in:
Your Name committed 2026-01-06 22:39:27 +08:00
1 parent a962a164e4
commit 68295e564e
9 files changed
+283 -135

No files matched your search

+7 -7
View File
@@ -7,7 +7,7 @@
"max_participants": 0,
"skip_if_countdown_gt_seconds": 180,
"reset_after_swipes_enabled": true,
"reset_after_swipes": 10,
"reset_after_swipes": 30,
"reset_after_swipes_action": "back",
"auto_join_fansclub": true,
"fansclub_fail_action": "switch",
@@ -30,8 +30,8 @@
"yanghao_fallback_enter_live_y": 1200,
"fudai_find_max_attempts": 99999,
"fudai_icon_retry_delay_seconds": 0.1,
"fudai_icon_max_wait_seconds": 6.5,
"fudai_click_wait_seconds": 1.0,
"fudai_icon_max_wait_seconds": 7.0,
"fudai_click_wait_seconds": 1.6,
"fudai_detail_initial_wait_seconds": 0.8,
"fudai_detail_verified_wait_seconds": 0.2,
"fudai_detail_retry_delay_seconds": 0.5,
@@ -151,9 +151,9 @@
"beautify_output": true,
"show_timestamps": true,
"show_execution_times": true,
"debug_detail_level": "normal",
"debug_detail_level": "minimal",
"error_detail_level": "full",
"action_log_format": "concise",
"action_log_format": "minimal",
"color_output": true,
"max_log_lines_display": 1000,
"auto_scroll_logs": true,
@@ -192,9 +192,9 @@
"async_save": false,
"log_on_complete": false
},
"fudai_detail_template_threshold": 0.53,
"fudai_detail_template_threshold": 0.52,
"switch_room_wait_after_stage_diag_seconds": 4.0,
"coupon_template_match_threshold": 0.37,
"coupon_template_match_threshold": 0.35,
"attend_button_red_ratio_threshold": 0.25,
"fansclub_join_red_ratio_threshold": 0.25,
"reservation_test_mode": false,
+11
View File
@@ -2316,6 +2316,11 @@ class fudai_analyse:
enter_live_y = int(382 * self.resolution_ratio_y // 2400)
self.operation.click(self.device_id, enter_live_x, enter_live_y)
self.operation.delay(self.ENTER_LIVE_CLICK_DELAY)
# 小延迟,避免界面卡顿导致第二次点击未生效
try:
self.operation.delay(getattr(self, "RETURN_STEP_DELAY_SECONDS", 0.8))
except Exception:
self.operation.delay(0.8)
self.operation.click(self.device_id, enter_live_x, enter_live_y)
self._log_kv(
"流程",
@@ -2324,6 +2329,12 @@ class fudai_analyse:
y=enter_live_y,
次数=2,
)
# 进入后等待(保留原有最终等待)
try:
# 小延迟,确保界面就绪(可配置)
self.operation.delay(getattr(self, "RETURN_STEP_DELAY_SECONDS", 0.8))
except Exception:
self.operation.delay(0.8)
self.operation.delay(self.ENTER_LIVE_FINAL_DELAY)
except Exception as e:
self._log_kv("流程", "处理推荐页面时出错", error=str(e))
+177 -107
View File
@@ -181,26 +181,14 @@ class SwipeHandler:
if swipe_times < threshold:
return swipe_times
# 防止回退过程中被重复触发(例如其他流程也触发返回键回退)
try:
analyser._log_kv( # type: ignore[attr-defined]
"流程",
"已切换直播间{}次,达到阈值{}:向上回退到第一个直播间".format(
swipe_times, threshold
),
swipe_times=swipe_times,
threshold=threshold,
)
if bool(getattr(analyser, "_resetting_after_swipes", False)):
return 0
setattr(analyser, "_resetting_after_swipes", True)
except Exception:
pass
# 回退次数按当前已切换次数来(更符合"回到本轮第一个直播间"的语义)
back_times = int(swipe_times)
# 防止无限循环:最大回退次数限制为100
if back_times > 100:
back_times = 100
if back_times <= 0:
return 0
# 根据配置选择回退方式:'swipe'=滑动回退(默认),'back'=按返回键回退
mode = str(
getattr(analyser, "reset_after_swipes_action", "swipe") or "swipe"
@@ -215,29 +203,81 @@ class SwipeHandler:
except Exception:
pass
if mode == "back":
# 使用返回键回退(兼容性更好,适用于无法通过滑动稳定回退的设备)
# 标记:开始通过滑动重置/回退流程,防止其他路径重复触发返回键
try:
import time as _time
try:
if mode == "back":
msg = "已切换直播间{}次,达到阈值{}:按一次返回键退出并重新进入直播间".format(
swipe_times, threshold
)
else:
msg = "已切换直播间{}次,达到阈值{}:向上滑动回退到第一个直播间".format(
swipe_times, threshold
)
analyser._log_kv( # type: ignore[attr-defined]
"流程",
msg,
swipe_times=swipe_times,
threshold=threshold,
reset_mode=mode,
)
except Exception:
pass
setattr(analyser, "_recent_reset_ts", _time.time())
setattr(analyser, "_recent_reset_by", "swipe_reset")
# 回退次数按当前已切换次数来(更符合"回到本轮第一个直播间"的语义)
back_times = int(swipe_times)
# 防止无限循环:最大回退次数限制为100
if back_times > 100:
back_times = 100
if back_times <= 0:
return 0
if mode == "back":
# 返回键回退:只按一次返回键退出直播间,然后重新进入直播间
try:
setattr(analyser, "_recent_reset_ts", time.time())
setattr(analyser, "_recent_reset_by", "reset_after_swipes_back_once")
except Exception:
pass
for i in range(back_times):
try:
analyser.operation.click_back(analyser.device_id)
except Exception:
pass
try:
analyser._log_kv( # type: ignore[attr-defined]
"流程",
"回退直播间 {}/{} (使用返回键)".format(i + 1, back_times),
)
except Exception:
pass
try:
analyser.operation.click_back(analyser.device_id)
except Exception:
pass
try:
analyser.operation.delay(getattr(analyser, "BACK_KEY_CLICK_DELAY", 2))
except Exception:
analyser.operation.delay(2)
# 小延迟,避免卡顿导致下一步截图/判断失败
try:
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
except Exception:
analyser.operation.delay(0.8)
# 尝试确认是否已回到推荐页;若不在推荐页,则兜底走原来的“多次返回到推荐页”逻辑
try:
ok = analyser.operation.get_screenshot(
analyser.device_id, use_service=False
)
if ok:
stage, seen = analyser._diagnose_stage_from_current_screen() # type: ignore[attr-defined]
if stage != "RECOMMEND_PAGE":
try:
analyser._log_kv( # type: ignore[attr-defined]
"流程",
"返回键回退后未到推荐页,兜底返回推荐页并重进直播",
stage=stage,
seen=seen,
)
except Exception:
pass
SwipeHandler.return_to_recommend_and_reenter_live(analyser)
else:
SwipeHandler._reenter_live_from_recommend(analyser)
else:
SwipeHandler.return_to_recommend_and_reenter_live(analyser)
except Exception:
SwipeHandler.return_to_recommend_and_reenter_live(analyser)
else:
try:
rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
@@ -247,6 +287,12 @@ class SwipeHandler:
for i in range(back_times):
try:
# 标记:本轮处于重置/回退流程中,防止其他路径触发返回键退出
try:
setattr(analyser, "_recent_reset_ts", time.time())
setattr(analyser, "_recent_reset_by", "reset_after_swipes_swipe")
except Exception:
pass
# 向上回退:从上往下滑动(start_y < end_y)
start_x = 760 * rx // 1080
start_y = 800 * ry // 2400 # 上方起始位置
@@ -275,10 +321,17 @@ class SwipeHandler:
subprocess.run(
cmd,
shell=True,
check=False,
timeout=5.0,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
# 注意:这里使用 ADB 直调绕过了 operation.swipe,需要手动标记页面已变化
try:
if hasattr(analyser.operation, "_mark_screen_dirty"):
analyser.operation._mark_screen_dirty(analyser.device_id)
except Exception:
pass
except Exception:
# 回退到 operation.swipe
analyser.operation.swipe(
@@ -310,8 +363,94 @@ class SwipeHandler:
pass
except Exception:
pass
finally:
try:
setattr(analyser, "_resetting_after_swipes", False)
except Exception:
pass
return 0
@staticmethod
def _reenter_live_from_recommend(analyser: Any) -> None:
"""从推荐页重新进入直播间(复用 return_to_recommend_and_reenter_live 的后半段逻辑)。"""
# 等待页面稳定
try:
analyser.operation.delay(getattr(analyser, "PAGE_STABLE_DELAY", 2))
except Exception:
analyser.operation.delay(2)
# 点击关注标签并进入直播间
try:
follow_tab_x = int(709 * analyser.resolution_ratio_x // 1080)
follow_tab_y = int(169 * analyser.resolution_ratio_y // 2400)
analyser.operation.click(analyser.device_id, follow_tab_x, follow_tab_y)
try:
analyser._log_kv( # type: ignore[attr-defined]
"流程", "点击关注标签", x=follow_tab_x, y=follow_tab_y
)
except Exception:
pass
try:
analyser.operation.delay(getattr(analyser, "FOLLOW_TAB_CLICK_DELAY", 2))
except Exception:
analyser.operation.delay(2)
# 小延迟,等待页面卡顿恢复再点击进入
try:
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
except Exception:
analyser.operation.delay(0.8)
enter_live_x = int(103 * analyser.resolution_ratio_x // 1080)
enter_live_y = int(385 * analyser.resolution_ratio_y // 2400)
analyser.operation.click(analyser.device_id, enter_live_x, enter_live_y)
try:
analyser.operation.delay(getattr(analyser, "ENTER_LIVE_CLICK_DELAY", 1))
except Exception:
analyser.operation.delay(1)
analyser.operation.click(analyser.device_id, enter_live_x, enter_live_y)
# 点击间隔稍微加长,避免卡顿导致第二次点击未生效
try:
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
except Exception:
analyser.operation.delay(0.8)
try:
analyser._log_kv( # type: ignore[attr-defined]
"流程",
"点击进入直播间位置",
x=enter_live_x,
y=enter_live_y,
次数=2,
)
except Exception:
pass
analyser.operation.delay(getattr(analyser, "ENTER_LIVE_FINAL_DELAY", 3))
try:
analyser._log_kv("流程", "已重新进入直播间") # type: ignore[attr-defined]
except Exception:
pass
try:
analyser._just_switched_room = True
except Exception:
pass
try:
analyser._last_successful_attend_ts = time.time()
analyser._run_start_ts = time.time()
except Exception:
pass
except Exception:
# 保守兜底:失败时尝试按一次返回键
try:
analyser.operation.click_back(analyser.device_id)
analyser.operation.delay(getattr(analyser, "BACK_KEY_CLICK_DELAY", 2))
except Exception:
pass
@staticmethod
@track_action("return_to_recommend_and_reenter_live")
def return_to_recommend_and_reenter_live(analyser: Any) -> None:
@@ -408,76 +547,7 @@ class SwipeHandler:
except Exception:
pass # 日志系统本身出错时忽略
# 点击关注标签并进入直播间(复用现有逻辑)
try:
# 点击关注标签 (709, 169) - 基于1080x2400分辨率
follow_tab_x = int(709 * analyser.resolution_ratio_x // 1080)
follow_tab_y = int(169 * analyser.resolution_ratio_y // 2400)
analyser.operation.click(analyser.device_id, follow_tab_x, follow_tab_y)
analyser._log_kv( # type: ignore[attr-defined]
"超时", "点击关注标签", x=follow_tab_x, y=follow_tab_y
)
analyser.operation.delay(analyser.FOLLOW_TAB_CLICK_DELAY)
# 点击进入直播间的位置 (103, 385),连点两次
enter_live_x = int(103 * analyser.resolution_ratio_x // 1080)
enter_live_y = int(385 * analyser.resolution_ratio_y // 2400)
analyser.operation.click(analyser.device_id, enter_live_x, enter_live_y)
analyser.operation.delay(analyser.ENTER_LIVE_CLICK_DELAY)
analyser.operation.click(analyser.device_id, enter_live_x, enter_live_y)
analyser._log_kv( # type: ignore[attr-defined]
"超时",
"点击进入直播间位置",
x=enter_live_x,
y=enter_live_y,
次数=2,
)
analyser.operation.delay(analyser.ENTER_LIVE_FINAL_DELAY)
analyser._log_kv("超时", "已重新进入直播间") # type: ignore[attr-defined]
# 标记刚刚切换进入直播间,后续读取标题时会等待标题区域出现
try:
analyser._just_switched_room = True
except Exception:
pass
# 重置超时相关时间戳(在成功重新进入直播间后重置,避免立即再次触发)
try:
analyser._last_successful_attend_ts = time.time()
analyser._run_start_ts = time.time()
except Exception as e:
try:
analyser._log_kv( # type: ignore[attr-defined]
"超时",
"重置时间戳时出错",
error=str(e),
error_type=type(e).__name__,
)
except Exception:
pass # 日志系统本身出错时忽略
except Exception as e:
# 记录异常但继续执行
try:
analyser._log_kv( # type: ignore[attr-defined]
"超时",
"重新进入直播间时出错",
error=str(e),
error_type=type(e).__name__,
)
except Exception:
pass # 日志系统本身出错时忽略
# 如果出错,尝试回退
try:
analyser.operation.click_back(analyser.device_id)
analyser.operation.delay(analyser.BACK_KEY_CLICK_DELAY)
except Exception as e2:
try:
analyser._log_kv( # type: ignore[attr-defined]
"超时",
"回退操作失败",
error=str(e2),
error_type=type(e2).__name__,
)
except Exception:
pass # 日志系统本身出错时忽略
SwipeHandler._reenter_live_from_recommend(analyser)
except Exception:
pass
+16 -4
View File
@@ -887,9 +887,15 @@ def yanghao_check_and_recover_from_desktop(analyser) -> bool:
ey = int(getattr(analyser, "yanghao_fallback_enter_live_y", 0) or 0)
print(f"[养号] 点击进入直播间 -> ({ex},{ey}) 连点两次")
analyser.click(ex, ey)
analyser.operation.delay(0.6)
try:
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
except Exception:
analyser.operation.delay(0.8)
analyser.click(ex, ey)
analyser.operation.delay(2.0)
try:
analyser.operation.delay(getattr(analyser, "ENTER_LIVE_FINAL_DELAY", 2.0))
except Exception:
analyser.operation.delay(2.0)
except Exception:
pass
return True
@@ -960,9 +966,15 @@ def yanghao_recommend_flow(analyser, total_seconds: int) -> None:
ey = int(getattr(analyser, "yanghao_fallback_enter_live_y", 0) or 0)
print("[养号] step5: 坐标点击进入直播间 -> ({},{}) 连点两次".format(ex, ey))
analyser.click(ex, ey)
analyser.operation.delay(0.6)
try:
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
except Exception:
analyser.operation.delay(0.8)
analyser.click(ex, ey)
analyser.operation.delay(2.0)
try:
analyser.operation.delay(getattr(analyser, "ENTER_LIVE_FINAL_DELAY", 2.0))
except Exception:
analyser.operation.delay(2.0)
if capture_steps:
analyser._save_step_screenshot("step5_enter")
print("[养号] 推荐页流程完成")
+28
View File
@@ -144,6 +144,34 @@ def extract_prize_value_yuan(text: str) -> float:
if not text:
return 0.0
s = unicodedata.normalize("NFKC", str(text))
# 纠正常见 OCR 对小数点与数字的识别错误
# 把常见的点类字符统一为英文句点 '.',把常见字母/符号的数字混淆做轻量替换
s = s.translate(
str.maketrans(
{
"·": ".",
".": ".",
"。": ".",
"・": ".",
"˙": ".",
"·": ".",
",": ",",
"O": "0",
"o": "0",
"Q": "0",
"D": "0",
"I": "1",
"l": "1",
"|": "1",
"!": "1",
"S": "5",
"s": "5",
"B": "8",
"G": "6",
"Z": "2",
}
)
)
values: list[float] = []
for idx, ch in enumerate(s):
+11 -4
View File
@@ -754,7 +754,13 @@ def main():
row.pack(fill=X, padx=10, pady=(10, 8))
ttk.Label(row, text="最低价值(元):").pack(side=LEFT)
ttk.Spinbox(
row, from_=0, to=99999, increment=1, textvariable=min_value_var, width=10
row,
from_=0,
to=99999,
increment=0.01,
format="%.2f",
textvariable=min_value_var,
width=10,
).pack(side=LEFT)
rowp = ttk.Frame(cfg_box)
@@ -943,7 +949,8 @@ def main():
res_r6,
from_=0,
to=99999,
increment=100,
increment=0.01,
format="%.2f",
textvariable=reservation_preempt_min_value_var,
width=10,
).pack(side=LEFT)
@@ -2477,12 +2484,12 @@ def main():
if "耗时" not in line:
return None
# 尝试提取耗时数字
m = re.search(r"耗时[:=]?\s*([0-9]+(?:\.[0-9]+)?)\s*s", line)
m = re.search(r"耗时[:=]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*s", line)
dur = None
if m:
dur = m.group(1) + "s"
else:
m2 = re.search(r"([0-9]+(?:\.[0-9]+)?)\s*s", line)
m2 = re.search(r"([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*s", line)
if m2:
dur = m2.group(1) + "s"
+6 -5
View File
@@ -289,10 +289,11 @@ class Runner:
# 奖品价值:支持多种格式
m = re.search(
r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s
r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)",
s,
)
if not m:
m = re.search(r"奖品价值:\s*([0-9]+(?:\.[0-9]+)?)\s*元", s)
m = re.search(r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s)
if m:
try:
with self._lock:
@@ -420,13 +421,13 @@ class Runner:
self._inc("fudai_skip_value_low")
# 提取实际价值和阈值
meta = self._snapshot_fudai()
m = re.search(r"(?:奖品)?价值[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
m = re.search(r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
if m:
try:
meta["prize_value_yuan"] = float(m.group(1))
except Exception:
pass
m = re.search(r"阈值[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
m = re.search(r"阈值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
if m:
try:
meta["threshold"] = float(m.group(1))
@@ -482,7 +483,7 @@ class Runner:
self._inc("fudai_reserved_high_value")
# 提取价值和倒计时信息
meta = self._snapshot_fudai()
m = re.search(r"(?:价值|价值元)[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
m = re.search(r"(?:价值|价值元)[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
if m:
try:
meta["prize_value_yuan"] = float(m.group(1))
+9 -8
View File
@@ -350,10 +350,11 @@ class ProcRunner:
# 奖品价值:支持多种格式
m = re.search(
r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s
r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)",
s,
)
if not m:
m = re.search(r"奖品价值:\s*([0-9]+(?:\.[0-9]+)?)\s*元", s)
m = re.search(r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s)
if m:
try:
self._fudai_last["prize_value_yuan"] = float(m.group(1))
@@ -429,13 +430,13 @@ class ProcRunner:
self._inc("fudai_skip_value_low")
# 提取实际价值和阈值
meta = self._snapshot_fudai()
m = re.search(r"(?:奖品)?价值[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
m = re.search(r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
if m:
try:
meta["prize_value_yuan"] = float(m.group(1))
except Exception:
pass
m = re.search(r"阈值[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
m = re.search(r"阈值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
if m:
try:
meta["threshold"] = float(m.group(1))
@@ -767,13 +768,13 @@ class ProcRunner:
m = re.search(r"阶段[=:]?\s*(\w+)", s)
if m:
meta["stage"] = m.group(1)
m = re.search(r"耗时[=:]?\s*([0-9]+(?:\.[0-9]+)?)\s*秒", s)
m = re.search(r"耗时[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*秒", s)
if m:
try:
meta["elapsed_seconds"] = float(m.group(1))
except Exception:
pass
m = re.search(r"分数[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
m = re.search(r"分数[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
if m:
try:
meta["score"] = float(m.group(1))
@@ -793,7 +794,7 @@ class ProcRunner:
self._inc("ocr_failed")
# --- 性能统计 ---
m = re.search(r"耗时[=:]?\s*([0-9]+(?:\.[0-9]+)?)\s*秒", s)
m = re.search(r"耗时[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*秒", s)
if m:
try:
elapsed = float(m.group(1))
@@ -854,7 +855,7 @@ class ProcRunner:
# --- 性能:进入直播间到识别福袋耗时 ---
m = re.search(
r"进入直播间到识别福袋耗时:\s*([0-9]+(?:\.[0-9]+)?)\s*秒(?:\s*进入原因=(.*))?",
r"进入直播间到识别福袋耗时:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*秒(?:\s*进入原因=(.*))?",
s,
)
if m:
+18
View File
@@ -0,0 +1,18 @@
from douyin.utils.douyin_utils import extract_prize_value_yuan
tests=[
'¥12.34',
'¥12·34',
'¥12.34',
'¥12.34',
'12.34元',
'12,345.67',
'¥O2.5O',
'¥1O.5',
'价值:12.5',
'价值12。5',
'价值12·5',
'随机文本 0.5 元',
]
for t in tests:
print(t, '->', extract_prize_value_yuan(t))