refactor(fudai): 抽 run_once_basic 中"FANSCLUB_JOIN"分支到 handle_fansclub_join
将 run_once_basic 中"粉丝团加入"分支(约 164 行)整段抽到 fudai_detail_helpers.handle_fansclub_join。逻辑: - 第一步:点击参与按钮(基于 OCR 区域中心 543, 2070) - 第二步:连续两次点击预设位置(527, 567) - 第三步:关闭详情页(点击 500, 470) - 异常分支:按 auto_join_fansclub 决定是否再次诊断 + 重试 + 点击返回 - 最终:按 fansclub_fail_action 决定是否切换直播间 douyin_fudai.py: 3447 → 3290 行 (-157) fudai_detail_helpers.py: 120 → 284 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
77351bafd4
commit
37b3454e32
2 files changed
+168
-161
No files matched your search
+4
-161
@@ -1831,168 +1831,11 @@ class fudai_analyse:
|
||||
)
|
||||
return
|
||||
elif stage == "FANSCLUB_JOIN":
|
||||
# 粉丝团加入阶段:先点击参与按钮,再点击两次预设位置,最后关闭详情页
|
||||
self._log_kv("粉丝团处理", "检测到粉丝团加入按钮,开始处理")
|
||||
try:
|
||||
# 第一步:先点击参与按钮(基于截图优化坐标:OCR区域(306,2030)-(780,2110),区域中心(543, 2070))
|
||||
attend_x = int(543 * self.resolution_ratio_x // 1080)
|
||||
attend_y = int(2070 * self.resolution_ratio_y // 2400)
|
||||
self.operation.click(self.device_id, attend_x, attend_y)
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"先点击参与按钮",
|
||||
x=attend_x,
|
||||
y=attend_y,
|
||||
base_x=543,
|
||||
base_y=2070,
|
||||
region="(306,2030)-(780,2110)",
|
||||
)
|
||||
self.operation.delay(0.5) # 等待参与按钮响应
|
||||
|
||||
# 第二步:点击两次预设位置(527, 567)
|
||||
preset_x = int(527 * self.resolution_ratio_x // 1080)
|
||||
preset_y = int(567 * self.resolution_ratio_y // 2400)
|
||||
|
||||
# 第一次点击预设位置
|
||||
self.operation.click(self.device_id, preset_x, preset_y)
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"第一次点击预设位置",
|
||||
x=preset_x,
|
||||
y=preset_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
self.operation.delay(0.5) # 短暂等待后立即第二次点击
|
||||
|
||||
# 第二次点击预设位置
|
||||
self.operation.click(self.device_id, preset_x, preset_y)
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"第二次点击预设位置",
|
||||
x=preset_x,
|
||||
y=preset_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
self.operation.delay(1.0) # 等待点击完成
|
||||
|
||||
# 第三步:关闭详情页(点击详情页旁边位置)
|
||||
close_x = int(500 * self.resolution_ratio_x // 1080)
|
||||
close_y = int(470 * self.resolution_ratio_y // 2400)
|
||||
self.operation.click(self.device_id, close_x, close_y)
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"关闭详情页",
|
||||
x=close_x,
|
||||
y=close_y,
|
||||
base_x=500,
|
||||
base_y=470,
|
||||
)
|
||||
self.operation.delay(1.0) # 等待关闭完成
|
||||
except Exception as exc:
|
||||
self._log_kv("粉丝团处理", "处理粉丝团加入失败", error=str(exc))
|
||||
|
||||
# 如果启用了自动加入,等待页面加载后再次点击(如果需要)
|
||||
if getattr(self, "auto_join_fansclub", False):
|
||||
self._log_kv("粉丝团处理", "已启用自动加入粉丝团,等待页面加载")
|
||||
self.operation.delay(1.0)
|
||||
# 再次诊断阶段,看是否还在粉丝团加入页
|
||||
try:
|
||||
stage_after, _ = self._diagnose_stage_from_current_screen()
|
||||
if stage_after == "FANSCLUB_JOIN":
|
||||
# 仍在粉丝团加入页,再次点击(连续点击两次)
|
||||
# 使用预设位置坐标(527, 567)
|
||||
preset_x = int(527 * self.resolution_ratio_x // 1080)
|
||||
preset_y = int(567 * self.resolution_ratio_y // 2400)
|
||||
self.operation.click(self.device_id, preset_x, preset_y)
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"仍在粉丝团加入页,再次第一次点击",
|
||||
x=preset_x,
|
||||
y=preset_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
self.operation.delay(0.5)
|
||||
self.operation.click(self.device_id, preset_x, preset_y)
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"仍在粉丝团加入页,再次第二次点击",
|
||||
x=preset_x,
|
||||
y=preset_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
self.operation.delay(2.0)
|
||||
|
||||
# 加入粉丝团成功后,点击 (527, 567) 返回直播间
|
||||
try:
|
||||
return_x = int(527 * self.resolution_ratio_x // 1080)
|
||||
return_y = int(567 * self.resolution_ratio_y // 2400)
|
||||
self.operation.click(self.device_id, return_x, return_y)
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"加入粉丝团成功后,点击返回直播间",
|
||||
x=return_x,
|
||||
y=return_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
self.operation.delay(1.0) # 等待返回完成
|
||||
except Exception as exc_inner:
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"点击返回直播间失败",
|
||||
error=str(exc_inner),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"未启用自动加入粉丝团,等待手动确认",
|
||||
wait_seconds=15,
|
||||
)
|
||||
self.operation.delay(15.0)
|
||||
|
||||
# 未启用自动加入时,也需要在等待后点击返回
|
||||
# 加入粉丝团成功后,点击 (527, 567) 返回直播间
|
||||
try:
|
||||
return_x = int(527 * self.resolution_ratio_x // 1080)
|
||||
return_y = int(567 * self.resolution_ratio_y // 2400)
|
||||
self.operation.click(self.device_id, return_x, return_y)
|
||||
self._log_kv(
|
||||
"粉丝团处理",
|
||||
"加入粉丝团成功后,点击返回直播间",
|
||||
x=return_x,
|
||||
y=return_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
self.operation.delay(1.0) # 等待返回完成
|
||||
except Exception as exc_inner2:
|
||||
self._log_kv(
|
||||
"粉丝团处理", "点击返回直播间失败", error=str(exc_inner2)
|
||||
)
|
||||
|
||||
# 延迟后返回,让主循环继续处理
|
||||
self.operation.delay(0.5)
|
||||
|
||||
# 如果失败,根据配置决定是否切换直播间
|
||||
fansclub_fail_action = getattr(self, "fansclub_fail_action", "stay")
|
||||
if fansclub_fail_action == "switch":
|
||||
self._log_kv("粉丝团处理", "粉丝团失败策略为switch,切换直播间")
|
||||
try:
|
||||
self.swipe_up_to_next_live()
|
||||
except Exception:
|
||||
pass
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"run_once_basic完成(处理粉丝团)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_fansclub_join,
|
||||
)
|
||||
|
||||
handle_fansclub_join(self, start_time)
|
||||
return
|
||||
elif stage == "FUDai_DETAIL":
|
||||
# 已经在详情页:直接按正常详情流程处理(已移除预约回退直接参与标志)
|
||||
|
||||
@@ -42,6 +42,170 @@ def log_screenshot_failed(
|
||||
pass
|
||||
|
||||
|
||||
def handle_fansclub_join(analyser, start_time: float) -> None:
|
||||
"""run_once_basic stage == "FANSCLUB_JOIN" 分支:
|
||||
|
||||
点击参与按钮 → 两次预设位置 → 关闭详情页。
|
||||
异常时按 auto_join_fansclub 决定是否再次诊断 + 重试 + 点击返回。
|
||||
最后按 fansclub_fail_action 决定是否切换直播间。
|
||||
调用方应在调用后立即 return。
|
||||
"""
|
||||
rx = analyser.resolution_ratio_x
|
||||
ry = analyser.resolution_ratio_y
|
||||
|
||||
analyser._log_kv("粉丝团处理", "检测到粉丝团加入按钮,开始处理")
|
||||
try:
|
||||
# 第一步:先点击参与按钮(OCR区域中心 543, 2070)
|
||||
attend_x = int(543 * rx // 1080)
|
||||
attend_y = int(2070 * ry // 2400)
|
||||
analyser.operation.click(analyser.device_id, attend_x, attend_y)
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"先点击参与按钮",
|
||||
x=attend_x,
|
||||
y=attend_y,
|
||||
base_x=543,
|
||||
base_y=2070,
|
||||
region="(306,2030)-(780,2110)",
|
||||
)
|
||||
analyser.operation.delay(0.5)
|
||||
|
||||
# 第二步:点击两次预设位置(527, 567)
|
||||
preset_x = int(527 * rx // 1080)
|
||||
preset_y = int(567 * ry // 2400)
|
||||
|
||||
analyser.operation.click(analyser.device_id, preset_x, preset_y)
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"第一次点击预设位置",
|
||||
x=preset_x,
|
||||
y=preset_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
analyser.operation.delay(0.5)
|
||||
|
||||
analyser.operation.click(analyser.device_id, preset_x, preset_y)
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"第二次点击预设位置",
|
||||
x=preset_x,
|
||||
y=preset_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
analyser.operation.delay(1.0)
|
||||
|
||||
# 第三步:关闭详情页
|
||||
close_x = int(500 * rx // 1080)
|
||||
close_y = int(470 * ry // 2400)
|
||||
analyser.operation.click(analyser.device_id, close_x, close_y)
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"关闭详情页",
|
||||
x=close_x,
|
||||
y=close_y,
|
||||
base_x=500,
|
||||
base_y=470,
|
||||
)
|
||||
analyser.operation.delay(1.0)
|
||||
except Exception as exc:
|
||||
analyser._log_kv("粉丝团处理", "处理粉丝团加入失败", error=str(exc))
|
||||
|
||||
if getattr(analyser, "auto_join_fansclub", False):
|
||||
analyser._log_kv("粉丝团处理", "已启用自动加入粉丝团,等待页面加载")
|
||||
analyser.operation.delay(1.0)
|
||||
try:
|
||||
stage_after, _ = analyser._diagnose_stage_from_current_screen()
|
||||
if stage_after == "FANSCLUB_JOIN":
|
||||
preset_x = int(527 * rx // 1080)
|
||||
preset_y = int(567 * ry // 2400)
|
||||
analyser.operation.click(analyser.device_id, preset_x, preset_y)
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"仍在粉丝团加入页,再次第一次点击",
|
||||
x=preset_x,
|
||||
y=preset_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
analyser.operation.delay(0.5)
|
||||
analyser.operation.click(analyser.device_id, preset_x, preset_y)
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"仍在粉丝团加入页,再次第二次点击",
|
||||
x=preset_x,
|
||||
y=preset_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
analyser.operation.delay(2.0)
|
||||
|
||||
try:
|
||||
return_x = int(527 * rx // 1080)
|
||||
return_y = int(567 * ry // 2400)
|
||||
analyser.operation.click(analyser.device_id, return_x, return_y)
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"加入粉丝团成功后,点击返回直播间",
|
||||
x=return_x,
|
||||
y=return_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
analyser.operation.delay(1.0)
|
||||
except Exception as exc_inner:
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"点击返回直播间失败",
|
||||
error=str(exc_inner),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"未启用自动加入粉丝团,等待手动确认",
|
||||
wait_seconds=15,
|
||||
)
|
||||
analyser.operation.delay(15.0)
|
||||
|
||||
try:
|
||||
return_x = int(527 * rx // 1080)
|
||||
return_y = int(567 * ry // 2400)
|
||||
analyser.operation.click(analyser.device_id, return_x, return_y)
|
||||
analyser._log_kv(
|
||||
"粉丝团处理",
|
||||
"加入粉丝团成功后,点击返回直播间",
|
||||
x=return_x,
|
||||
y=return_y,
|
||||
base_x=527,
|
||||
base_y=567,
|
||||
)
|
||||
analyser.operation.delay(1.0)
|
||||
except Exception as exc_inner2:
|
||||
analyser._log_kv(
|
||||
"粉丝团处理", "点击返回直播间失败", error=str(exc_inner2)
|
||||
)
|
||||
|
||||
analyser.operation.delay(0.5)
|
||||
|
||||
fansclub_fail_action = getattr(analyser, "fansclub_fail_action", "stay")
|
||||
if fansclub_fail_action == "switch":
|
||||
analyser._log_kv("粉丝团处理", "粉丝团失败策略为switch,切换直播间")
|
||||
try:
|
||||
analyser.swipe_up_to_next_live()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"run_once_basic完成(处理粉丝团)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
)
|
||||
|
||||
|
||||
def clear_task_count_flag(analyser) -> None:
|
||||
"""清除任务数量标志(_fudai_detail_task_count_from_stage = None)。
|
||||
|
||||
|
||||
Reference in new issue
Block a user