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:检测是否意外返回桌面(不在抖音前台)并尝试恢复。