From c6eb76845f0259850efff04cda396e4f58ec9a39 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 6 Jan 2026 22:39:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E6=8F=90=E5=8D=87=E5=8F=AF=E8=AF=BB?= =?UTF-8?q?=E6=80=A7=E5=92=8C=E4=B8=80=E8=87=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/core/douyin_fudai.py | 8 +++++-- douyin/handlers/douyin_swipe_handler.py | 20 +++++++++++++----- douyin/other/douyin_yanghao.py | 12 ++++++++--- gui/gui_app.py | 8 +++++-- gui/gui_core.py | 17 +++++++++++---- gui/web_gui.py | 25 ++++++++++++++++------ tools/test_extract_prize.py | 28 ++++++++++++------------- 7 files changed, 82 insertions(+), 36 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 5df2fa1..70a84eb 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -2318,7 +2318,9 @@ class fudai_analyse: self.operation.delay(self.ENTER_LIVE_CLICK_DELAY) # 小延迟,避免界面卡顿导致第二次点击未生效 try: - self.operation.delay(getattr(self, "RETURN_STEP_DELAY_SECONDS", 0.8)) + 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) @@ -2332,7 +2334,9 @@ class fudai_analyse: # 进入后等待(保留原有最终等待) try: # 小延迟,确保界面就绪(可配置) - self.operation.delay(getattr(self, "RETURN_STEP_DELAY_SECONDS", 0.8)) + 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) diff --git a/douyin/handlers/douyin_swipe_handler.py b/douyin/handlers/douyin_swipe_handler.py index 7d9c753..62d7b94 100644 --- a/douyin/handlers/douyin_swipe_handler.py +++ b/douyin/handlers/douyin_swipe_handler.py @@ -250,7 +250,9 @@ class SwipeHandler: # 小延迟,避免卡顿导致下一步截图/判断失败 try: - analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)) + analyser.operation.delay( + getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8) + ) except Exception: analyser.operation.delay(0.8) @@ -290,7 +292,9 @@ class SwipeHandler: # 标记:本轮处于重置/回退流程中,防止其他路径触发返回键退出 try: setattr(analyser, "_recent_reset_ts", time.time()) - setattr(analyser, "_recent_reset_by", "reset_after_swipes_swipe") + setattr( + analyser, "_recent_reset_by", "reset_after_swipes_swipe" + ) except Exception: pass # 向上回退:从上往下滑动(start_y < end_y) @@ -329,7 +333,9 @@ class SwipeHandler: # 注意:这里使用 ADB 直调绕过了 operation.swipe,需要手动标记页面已变化 try: if hasattr(analyser.operation, "_mark_screen_dirty"): - analyser.operation._mark_screen_dirty(analyser.device_id) + analyser.operation._mark_screen_dirty( + analyser.device_id + ) except Exception: pass except Exception: @@ -397,7 +403,9 @@ class SwipeHandler: # 小延迟,等待页面卡顿恢复再点击进入 try: - analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)) + analyser.operation.delay( + getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8) + ) except Exception: analyser.operation.delay(0.8) @@ -412,7 +420,9 @@ class SwipeHandler: # 点击间隔稍微加长,避免卡顿导致第二次点击未生效 try: - analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)) + analyser.operation.delay( + getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8) + ) except Exception: analyser.operation.delay(0.8) diff --git a/douyin/other/douyin_yanghao.py b/douyin/other/douyin_yanghao.py index 50351a6..6eccc30 100644 --- a/douyin/other/douyin_yanghao.py +++ b/douyin/other/douyin_yanghao.py @@ -888,12 +888,16 @@ def yanghao_check_and_recover_from_desktop(analyser) -> bool: print(f"[养号] 点击进入直播间 -> ({ex},{ey}) 连点两次") analyser.click(ex, ey) try: - analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)) + analyser.operation.delay( + getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8) + ) except Exception: analyser.operation.delay(0.8) analyser.click(ex, ey) try: - analyser.operation.delay(getattr(analyser, "ENTER_LIVE_FINAL_DELAY", 2.0)) + analyser.operation.delay( + getattr(analyser, "ENTER_LIVE_FINAL_DELAY", 2.0) + ) except Exception: analyser.operation.delay(2.0) except Exception: @@ -967,7 +971,9 @@ def yanghao_recommend_flow(analyser, total_seconds: int) -> None: print("[养号] step5: 坐标点击进入直播间 -> ({},{}) 连点两次".format(ex, ey)) analyser.click(ex, ey) try: - analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)) + analyser.operation.delay( + getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8) + ) except Exception: analyser.operation.delay(0.8) analyser.click(ex, ey) diff --git a/gui/gui_app.py b/gui/gui_app.py index db22ed1..9c72933 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -2484,12 +2484,16 @@ def main(): if "耗时" not in line: return None # 尝试提取耗时数字 - m = re.search(r"耗时[:=]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][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]+(?:[.\u00B7\uFF0E\uFF61·.。][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" diff --git a/gui/gui_core.py b/gui/gui_core.py index deeab78..1eea173 100644 --- a/gui/gui_core.py +++ b/gui/gui_core.py @@ -293,7 +293,9 @@ class Runner: s, ) if not m: - m = re.search(r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s) + m = re.search( + r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s + ) if m: try: with self._lock: @@ -421,13 +423,17 @@ class Runner: self._inc("fudai_skip_value_low") # 提取实际价值和阈值 meta = self._snapshot_fudai() - m = re.search(r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][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]+(?:[.\u00B7\uFF0E\uFF61·.。][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)) @@ -483,7 +489,10 @@ class Runner: self._inc("fudai_reserved_high_value") # 提取价值和倒计时信息 meta = self._snapshot_fudai() - m = re.search(r"(?:价值|价值元)[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][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)) diff --git a/gui/web_gui.py b/gui/web_gui.py index 1caa331..5adb892 100644 --- a/gui/web_gui.py +++ b/gui/web_gui.py @@ -354,7 +354,9 @@ class ProcRunner: s, ) if not m: - m = re.search(r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][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)) @@ -430,13 +432,17 @@ class ProcRunner: self._inc("fudai_skip_value_low") # 提取实际价值和阈值 meta = self._snapshot_fudai() - m = re.search(r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][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]+(?:[.\u00B7\uFF0E\uFF61·.。][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)) @@ -768,13 +774,17 @@ class ProcRunner: m = re.search(r"阶段[=:]?\s*(\w+)", s) if m: meta["stage"] = m.group(1) - m = re.search(r"耗时[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][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]+(?:[.\u00B7\uFF0E\uFF61·.。][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)) @@ -794,7 +804,9 @@ class ProcRunner: self._inc("ocr_failed") # --- 性能统计 --- - m = re.search(r"耗时[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][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)) @@ -1899,6 +1911,7 @@ class Handler(BaseHTTPRequestHandler): self.send_error(HTTPStatus.NOT_FOUND) + def main() -> int: host = "127.0.0.1" # 支持 PORT / WEB_GUI_PORT 两种环境变量,默认 8000 diff --git a/tools/test_extract_prize.py b/tools/test_extract_prize.py index 917004b..353a323 100644 --- a/tools/test_extract_prize.py +++ b/tools/test_extract_prize.py @@ -1,18 +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 元', +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)) + print(t, "->", extract_prize_value_yuan(t))