From 241c35f21d49875bf0728c0ad145179ffe4cfcb0 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 11:47:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20=5Fhandle=5Fin?= =?UTF-8?q?=5Ffudai=5Fdetail=20=E4=B8=AD"=E5=85=9C=E5=BA=95=E4=B8=8A?= =?UTF-8?q?=E6=BB=91=E5=88=87=E6=88=BF"=E5=9D=97=E5=88=B0=20fallback=5Fswi?= =?UTF-8?q?pe=5Fup=5Fto=5Fnext=5Flive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将筛选不通过后的兜底切换逻辑(67 行深度嵌套)抽到 fudai_detail_helpers.fallback_swipe_up_to_next_live。逻辑: - 优先 swipe_up_to_next_live - 兜底直接调用 ADB shell input swipe(基于 1080x2400 基准坐标缩放) - 最终回退到 operation.swipe douyin_fudai.py: 2400 → 2336 行 (-64) fudai_detail_helpers.py: 1403 → 1468 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 74 ++----------------- .../fudai_modules/fudai_detail_helpers.py | 65 ++++++++++++++++ 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 8569a04..6e5c3fb 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1608,75 +1608,11 @@ class fudai_analyse: except Exception: pass try: - # 优先使用封装好的上滑切房方法 - if hasattr(self, "swipe_up_to_next_live"): - self.swipe_up_to_next_live() - else: - # 兜底:直接调用底层 swipe(基于 1080x2400 基准坐标) - try: - rx = int( - getattr( - self, "resolution_ratio_x", 1080 - ) - or 1080 - ) - ry = int( - getattr( - self, "resolution_ratio_y", 2400 - ) - or 2400 - ) - except Exception: - rx, ry = 1080, 2400 - start_x = 540 * rx // 1080 - start_y = 1200 * ry // 2400 - end_x = 540 * rx // 1080 - end_y = 600 * ry // 2400 - # 直接使用 ADB 内部滑动命令 - try: - if hasattr(self.operation, "_adb_path"): - adb_cmd = self.operation._adb_path() - else: - adb_cmd = ( - os.environ.get( - "ADB_EXECUTABLE", "adb" - ) - or "adb" - ) - if adb_cmd.startswith( - '"' - ) and adb_cmd.endswith('"'): - adb_cmd = adb_cmd[1:-1] - cmd = [ - adb_cmd, - "-s", - str(self.device_id), - "shell", - "input", - "swipe", - str(int(start_x)), - str(int(start_y)), - str(int(end_x)), - str(int(end_y)), - "300", - ] - subprocess.run( - cmd, - timeout=5.0, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - check=False, - ) - except Exception: - # 回退到 operation.swipe - self.operation.swipe( - self.device_id, - start_x, - start_y, - end_x, - end_y, - 300, - ) + from douyin.core.fudai_modules.fudai_detail_helpers import ( + fallback_swipe_up_to_next_live, + ) + + fallback_swipe_up_to_next_live(self) except Exception: pass diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index a9fcfa5..c9101d4 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,71 @@ def log_screenshot_failed( pass +def fallback_swipe_up_to_next_live(analyser) -> None: + """兜底版上滑切换直播间:当 swipe_up_to_next_live 不可用时使用。 + + 1. 优先用封装好的 swipe_up_to_next_live 方法 + 2. 兜底:基于 1080x2400 基准坐标计算实际坐标 + 直接调用 ADB swipe 命令 + 3. 最终兜底:调用 operation.swipe + """ + import os + import subprocess + + if hasattr(analyser, "swipe_up_to_next_live"): + analyser.swipe_up_to_next_live() + return + + try: + rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080) + ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400) + except Exception: + rx, ry = 1080, 2400 + + start_x = 540 * rx // 1080 + start_y = 1200 * ry // 2400 + end_x = 540 * rx // 1080 + end_y = 600 * ry // 2400 + + # 优先使用 ADB 内部滑动命令 + try: + if hasattr(analyser.operation, "_adb_path"): + adb_cmd = analyser.operation._adb_path() + else: + adb_cmd = os.environ.get("ADB_EXECUTABLE", "adb") or "adb" + if adb_cmd.startswith('"') and adb_cmd.endswith('"'): + adb_cmd = adb_cmd[1:-1] + cmd = [ + adb_cmd, + "-s", + str(analyser.device_id), + "shell", + "input", + "swipe", + str(int(start_x)), + str(int(start_y)), + str(int(end_x)), + str(int(end_y)), + "300", + ] + subprocess.run( + cmd, + timeout=5.0, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=False, + ) + except Exception: + # 最终回退到 operation.swipe + analyser.operation.swipe( + analyser.device_id, + start_x, + start_y, + end_x, + end_y, + 300, + ) + + def log_handle_in_fudai_detail_entry(analyser) -> None: """_handle_in_fudai_detail 入口诊断日志:记录当前关键 flags。""" try: