refactor(fudai): 抽 _handle_live_room_has_or_not_fudai 中两块到 helper

- try_skip_to_in_fudai_detail_when_verified(约 22 行):已验证过详情页则直接处理详情
- handle_no_fudai_in_live_room(约 35 行):无福袋时调用 flow_control 处理 + 写完成日志

douyin_fudai.py: 1404 → 1355 行 (-49)
fudai_detail_helpers.py: 2659 → 2742 行

douyin_fudai.py 跌破 1400 行(4121 → 1355,本会话累计削减 2766 行 = -67%)
_handle_live_room_has_or_not_fudai 从 90 行 → 41 行

验证:
- 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 12:33:25 +08:00
1 parent d9323f2012
commit 2ba2168665
2 files changed
+95 -61

No files matched your search

+12 -61
View File
@@ -1317,31 +1317,14 @@ class fudai_analyse:
start_time = time.time()
# 设置当前参与的福袋类型为高价值福袋(非预约)
self._current_attending_reservation_fudai = False
# 先检查是否已经在福袋详情页(可能阶段诊断没有正确识别)
# 如果已验证过详情页但任务数为0,说明详情页正在加载,不应该再次查找福袋
try:
already_verified = bool(
getattr(self, "_fudai_detail_verified", False) or False
)
if already_verified:
try:
self._log_kv(
"流程",
"_handle_live_room_has_or_not_fudai:已验证过详情页,直接处理详情,不查找福袋",
)
except Exception:
pass
# 直接调用详情处理逻辑,不查找福袋
self._handle_in_fudai_detail()
elapsed = time.time() - start_time
self._log_kv(
"流程",
"_handle_live_room_has_or_not_fudai完成(已验证详情页)",
elapsed_seconds=round(elapsed, 2),
)
return
except Exception:
pass
from douyin.core.fudai_modules.fudai_detail_helpers import (
try_skip_to_in_fudai_detail_when_verified,
)
if try_skip_to_in_fudai_detail_when_verified(self, start_time):
return
# 检查是否在锁定期内,且时间窗口未到,避免重复打开福袋详情
from douyin.core.fudai_modules.fudai_detail_helpers import (
@@ -1354,44 +1337,12 @@ class fudai_analyse:
room_pos_ref: List[int] = [0]
opened = douyin_flow_control.find_and_open_fudai_detail(self, room_pos_ref)
if not opened:
# 无福袋,交给 flow_control 的“无福袋处理”逻辑
# 根据配置决定是否允许切换直播间(needswitch=False 时只等待不切房)
try:
need_switch_config = bool(getattr(self, "needswitch", True))
except Exception:
need_switch_config = True
# 无福袋,交给 flow_control 的"无福袋处理"逻辑
from douyin.core.fudai_modules.fudai_detail_helpers import (
handle_no_fudai_in_live_room,
)
wait_times_ref = [0]
swipe_times_ref = [0]
reservation_focus_until_ts_ref = [0.0]
reset_to_list_after_reservations_ref = [False]
douyin_flow_control.handle_no_fudai_situation(
self,
x=0,
swipe_times=0,
wait_times_ref=wait_times_ref,
needswitch=need_switch_config,
reservation_focus_until_ts=0.0,
reservations=[],
room_pos=room_pos_ref[0],
post_switch_delay_s=1.5,
swipe_up_switch_callback=self.swipe_up_to_next_live,
swipe_down_back_callback=lambda: None,
sort_reservations_callback=lambda: None,
clear_reservations_callback=lambda: None,
write_state_callback=lambda: None,
back_to_list_callback=lambda: None,
into_list_callback=lambda: None,
reservation_focus_until_ts_ref=reservation_focus_until_ts_ref,
reset_to_list_after_reservations_ref=reset_to_list_after_reservations_ref,
swipe_times_ref=swipe_times_ref,
)
elapsed = time.time() - start_time
self._log_kv(
"流程",
"_handle_live_room_has_or_not_fudai完成(无福袋)",
elapsed_seconds=round(elapsed, 2),
)
handle_no_fudai_in_live_room(self, room_pos_ref, start_time)
return
# 成功打开详情:调用同一套详情处理逻辑
@@ -42,6 +42,89 @@ def log_screenshot_failed(
pass
def try_skip_to_in_fudai_detail_when_verified(analyser, start_time: float) -> bool:
"""_handle_live_room_has_or_not_fudai 入口:如果已验证过详情页,直接处理详情。
返回:
True:已转到详情处理(调用方应直接 return)
False:未验证或异常,调用方继续查找福袋
"""
try:
already_verified = bool(
getattr(analyser, "_fudai_detail_verified", False) or False
)
if not already_verified:
return False
try:
analyser._log_kv(
"流程",
"_handle_live_room_has_or_not_fudai:已验证过详情页,直接处理详情,不查找福袋",
)
except Exception:
pass
analyser._handle_in_fudai_detail()
elapsed = time.time() - start_time
analyser._log_kv(
"流程",
"_handle_live_room_has_or_not_fudai完成(已验证详情页)",
elapsed_seconds=round(elapsed, 2),
)
return True
except Exception:
pass
return False
def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> None:
"""_handle_live_room_has_or_not_fudai:无福袋时调用 flow_control 处理。
流程:
- 按 needswitch 决定是否允许切换直播间
- 调用 douyin_flow_control.handle_no_fudai_situation
- 写完成日志
"""
from douyin.detection import douyin_flow_control
try:
need_switch_config = bool(getattr(analyser, "needswitch", True))
except Exception:
need_switch_config = True
wait_times_ref = [0]
swipe_times_ref = [0]
reservation_focus_until_ts_ref = [0.0]
reset_to_list_after_reservations_ref = [False]
douyin_flow_control.handle_no_fudai_situation(
analyser,
x=0,
swipe_times=0,
wait_times_ref=wait_times_ref,
needswitch=need_switch_config,
reservation_focus_until_ts=0.0,
reservations=[],
room_pos=room_pos_ref[0],
post_switch_delay_s=1.5,
swipe_up_switch_callback=analyser.swipe_up_to_next_live,
swipe_down_back_callback=lambda: None,
sort_reservations_callback=lambda: None,
clear_reservations_callback=lambda: None,
write_state_callback=lambda: None,
back_to_list_callback=lambda: None,
into_list_callback=lambda: None,
reservation_focus_until_ts_ref=reservation_focus_until_ts_ref,
reset_to_list_after_reservations_ref=reset_to_list_after_reservations_ref,
swipe_times_ref=swipe_times_ref,
)
elapsed = time.time() - start_time
analyser._log_kv(
"流程",
"_handle_live_room_has_or_not_fudai完成(无福袋)",
elapsed_seconds=round(elapsed, 2),
)
def record_room_title_if_not_just_switched(analyser) -> None:
"""run_once_basic 入口:尝试记录当前直播间的标题与位置。