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。