From da552d18cc151a469e23920f85ce6e8c1ebfafd8 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 11:09:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20run=5Fonce=5Fbas?= =?UTF-8?q?ic=20=E4=B8=AD"RECOMMEND=5FPAGE"=E5=88=86=E6=94=AF=E5=88=B0=20h?= =?UTF-8?q?andle=5Frecommend=5Fpage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将识别到推荐页面后的处理逻辑(约 56 行)抽到 fudai_detail_helpers.handle_recommend_page。逻辑: - 点击进入直播页 (718, 169) - 连点两次进入直播间 (103, 382) - 多段延迟(FOLLOW_TAB_CLICK_DELAY / ENTER_LIVE_CLICK_DELAY / RETURN_STEP_DELAY_SECONDS / ENTER_LIVE_FINAL_DELAY) - 异常时按返回键 + delay 1s douyin_fudai.py: 3132 → 3092 行 (-40) fudai_detail_helpers.py: 477 → 535 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 48 ++------------- .../fudai_modules/fudai_detail_helpers.py | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+), 44 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 0cc7384..e31adec 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1751,51 +1751,11 @@ class fudai_analyse: stage=stage, seen=seen, ) - try: - # 直接点击 (718, 169) 进入直播页 - 基于1080x2400分辨率 - live_tab_x = int(718 * self.resolution_ratio_x // 1080) - live_tab_y = int(169 * self.resolution_ratio_y // 2400) - self.operation.click(self.device_id, live_tab_x, live_tab_y) - self._log_kv("流程", "点击进入直播页", x=live_tab_x, y=live_tab_y) - self.operation.delay(self.FOLLOW_TAB_CLICK_DELAY) + from douyin.core.fudai_modules.fudai_detail_helpers import ( + handle_recommend_page, + ) - # 点击进入直播间的位置 (103, 382),连点两次 - enter_live_x = int(103 * self.resolution_ratio_x // 1080) - 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( - "流程", - "点击进入直播间位置", - x=enter_live_x, - 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)) - # 如果出错,尝试回退 - try: - self.operation.click_back(self.device_id) - self.operation.delay(1.0) - except Exception: - pass + handle_recommend_page(self) else: # 其他列表页:使用原有逻辑 douyin_live_room.reflash_zhibo(self) diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 3d555e6..6d3d899 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,64 @@ def log_screenshot_failed( pass +def handle_recommend_page(analyser) -> None: + """run_once_basic stage == "RECOMMEND_PAGE" 分支: + + 点击进入直播页(718, 169) → 连点两次进入直播间(103, 382) → 等待。 + 所有坐标按 resolution_ratio_x/y 缩放。 + """ + rx = analyser.resolution_ratio_x + ry = analyser.resolution_ratio_y + + try: + # 直接点击 (718, 169) 进入直播页 - 基于1080x2400分辨率 + live_tab_x = int(718 * rx // 1080) + live_tab_y = int(169 * ry // 2400) + analyser.operation.click(analyser.device_id, live_tab_x, live_tab_y) + analyser._log_kv("流程", "点击进入直播页", x=live_tab_x, y=live_tab_y) + analyser.operation.delay(analyser.FOLLOW_TAB_CLICK_DELAY) + + # 点击进入直播间的位置 (103, 382),连点两次 + enter_live_x = int(103 * rx // 1080) + enter_live_y = int(382 * ry // 2400) + analyser.operation.click(analyser.device_id, enter_live_x, enter_live_y) + analyser.operation.delay(analyser.ENTER_LIVE_CLICK_DELAY) + + # 小延迟,避免界面卡顿导致第二次点击未生效 + try: + analyser.operation.delay( + getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8) + ) + except Exception: + analyser.operation.delay(0.8) + + analyser.operation.click(analyser.device_id, enter_live_x, enter_live_y) + analyser._log_kv( + "流程", + "点击进入直播间位置", + x=enter_live_x, + y=enter_live_y, + 次数=2, + ) + + # 进入后等待(保留原有最终等待) + try: + analyser.operation.delay( + getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8) + ) + except Exception: + analyser.operation.delay(0.8) + analyser.operation.delay(analyser.ENTER_LIVE_FINAL_DELAY) + except Exception as e: + analyser._log_kv("流程", "处理推荐页面时出错", error=str(e)) + # 如果出错,尝试回退 + try: + analyser.operation.click_back(analyser.device_id) + analyser.operation.delay(1.0) + except Exception: + pass + + def try_desktop_recovery(analyser) -> bool: """run_once_basic 步骤 1.5:检测是否意外返回桌面(不在抖音前台)并尝试恢复。