refactor(fudai): 抽 run_once_basic 中"RECOMMEND_PAGE"分支到 handle_recommend_page

将识别到推荐页面后的处理逻辑(约 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) <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.7 committed 2026-05-22 11:09:26 +08:00
1 parent 40b4169aac
commit da552d18cc
2 files changed
+62 -44

No files matched your search

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