From 42ef73a9ee651207076e176dff8d0ce115512673 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 13:30:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20fudai=5Fanalyse.?= =?UTF-8?q?swipe=20=E5=AE=9E=E7=8E=B0=E5=88=B0=20swipe=5Fwith=5Ffallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 swipe 方法体(约 60 行)抽到 fudai_detail_helpers.swipe_with_fallback。 逻辑: - 首选 operation.swipe - 失败回退到 douyin_swipe_ops._adb_swipe_direct - 最后兜底记录"swipe 失败"日志 类内 swipe 方法保留薄包装。 douyin_fudai.py: 1132 → 1078 行 (-54) fudai_detail_helpers.py: 2975 → 3033 行 douyin_fudai.py 跌破 1100 行(4121 → 1078,本会话累计削减 3043 行 = -74%) 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 60 +------------------ .../fudai_modules/fudai_detail_helpers.py | 58 ++++++++++++++++++ 2 files changed, 61 insertions(+), 57 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 3b28ee4..e1dce9b 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -250,64 +250,10 @@ class fudai_analyse: def swipe( self, start_x: int, start_y: int, end_x: int, end_y: int, duration_ms: int = 300 ) -> None: - """兼容原版 fudai_analyse.swipe:转发到底层 operation.swipe。 + """兼容原版 fudai_analyse.swipe:转发到底层 operation.swipe。""" + from douyin.core.fudai_modules.fudai_detail_helpers import swipe_with_fallback - 参数使用像素坐标,duration_ms 为滑动持续时间(毫秒)。 - """ - try: - # 首选底层 operation 的 swipe 实现 - try: - self.operation.swipe( - self.device_id, start_x, start_y, end_x, end_y, duration_ms - ) - return - except Exception: - pass - - # 回退:尝试使用 douyin.handlers.douyin_swipe_ops 的 adb 命令直接发送 - try: - from douyin.handlers import douyin_swipe_ops - - ok = douyin_swipe_ops._adb_swipe_direct( - getattr(self, "device_id", ""), - start_x, - start_y, - end_x, - end_y, - duration_ms, - self.operation, - ) - if ok: - return - except Exception: - pass - - # 最后兜底:记录滑动失败 - try: - self._log_kv( - "滑动", - "swipe 失败 - 无可用实现", - start_x=start_x, - start_y=start_y, - end_x=end_x, - end_y=end_y, - duration_ms=duration_ms, - ) - except Exception: - pass - except Exception: - try: - self._log_kv( - "滑动", - "swipe 异常", - start_x=start_x, - start_y=start_y, - end_x=end_x, - end_y=end_y, - duration_ms=duration_ms, - ) - except Exception: - pass + swipe_with_fallback(self, start_x, start_y, end_x, end_y, duration_ms) def load_config(self) -> None: """从 config.json 加载与福袋筛选/节流相关的关键参数(精简版)。""" diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 5a07680..859fca5 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -273,6 +273,64 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N ) +def swipe_with_fallback(analyser, start_x: int, start_y: int, end_x: int, end_y: int, duration_ms: int = 300) -> None: + """fudai_analyse.swipe 的实现:转发到底层 operation.swipe,失败时回退到 ADB direct。""" + try: + # 首选底层 operation 的 swipe 实现 + try: + analyser.operation.swipe( + analyser.device_id, start_x, start_y, end_x, end_y, duration_ms + ) + return + except Exception: + pass + + # 回退:尝试使用 douyin.handlers.douyin_swipe_ops 的 adb 命令直接发送 + try: + from douyin.handlers import douyin_swipe_ops + + ok = douyin_swipe_ops._adb_swipe_direct( + getattr(analyser, "device_id", ""), + start_x, + start_y, + end_x, + end_y, + duration_ms, + analyser.operation, + ) + if ok: + return + except Exception: + pass + + # 最后兜底:记录滑动失败 + try: + analyser._log_kv( + "滑动", + "swipe 失败 - 无可用实现", + start_x=start_x, + start_y=start_y, + end_x=end_x, + end_y=end_y, + duration_ms=duration_ms, + ) + except Exception: + pass + except Exception: + try: + analyser._log_kv( + "滑动", + "swipe 异常", + start_x=start_x, + start_y=start_y, + end_x=end_x, + end_y=end_y, + duration_ms=duration_ms, + ) + except Exception: + pass + + def dispatch_stage(analyser, stage: str, seen: str, start_time: float) -> None: """run_once_basic 阶段分发器:根据 stage 调用对应的 helper。