diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 446d5a9..75bd792 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1707,40 +1707,11 @@ class fudai_analyse: except Exception: pass - # 在直播间:如果刚刚切换了直播间,等待福袋加载 - just_switched = getattr(self, "_just_switched_room", False) - if just_switched: - try: - self._just_switched_room = False # 清除标志 - wait_seconds = float( - getattr(self, "switch_room_wait_after_stage_diag_seconds", 7.0) - or 7.0 - ) - if wait_seconds > 0: - self._log_kv( - "流程", - "切换直播间后,阶段检测完成,等待福袋加载", - wait_seconds=wait_seconds, - ) - self.operation.delay(wait_seconds) - except Exception as e: - try: - self._just_switched_room = False # 确保清除标志 - self._log_kv("流程", "等待福袋加载时出错", error=str(e)) - except Exception: - pass - - # 在直播间:寻找福袋图标并尝试点开 - fudai_search_start = time.time() - self._handle_live_room_has_or_not_fudai() - fudai_search_elapsed = time.time() - fudai_search_start - self._log_kv("福袋查找", f"福袋查找完成,耗时: {fudai_search_elapsed:.3f}s") - 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_in_live_room_stage, ) + + handle_in_live_room_stage(self, start_time) elif stage in ("RECOMMEND_PAGE", "FOLLOW_LIST", "LIVE_LIST"): # 处理推荐/关注/直播列表页:回到直播间或切换 if stage == "RECOMMEND_PAGE": diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index b66cebb..05ae698 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,52 @@ def log_screenshot_failed( pass +def handle_in_live_room_stage(analyser, start_time: float) -> None: + """run_once_basic stage in ("IN_LIVE_ROOM", "LIVE_OR_UNKNOWN") 分支: + + - 如果刚切换直播间(_just_switched_room=True),等待福袋加载 + (switch_room_wait_after_stage_diag_seconds 秒) + - 调用 _handle_live_room_has_or_not_fudai 寻找福袋图标 + - 写完成日志 + """ + # 如果刚刚切换了直播间,等待福袋加载 + just_switched = getattr(analyser, "_just_switched_room", False) + if just_switched: + try: + analyser._just_switched_room = False + wait_seconds = float( + getattr(analyser, "switch_room_wait_after_stage_diag_seconds", 7.0) + or 7.0 + ) + if wait_seconds > 0: + analyser._log_kv( + "流程", + "切换直播间后,阶段检测完成,等待福袋加载", + wait_seconds=wait_seconds, + ) + analyser.operation.delay(wait_seconds) + except Exception as e: + try: + analyser._just_switched_room = False + analyser._log_kv("流程", "等待福袋加载时出错", error=str(e)) + except Exception: + pass + + # 在直播间:寻找福袋图标并尝试点开 + fudai_search_start = time.time() + analyser._handle_live_room_has_or_not_fudai() + fudai_search_elapsed = time.time() - fudai_search_start + analyser._log_kv( + "福袋查找", f"福袋查找完成,耗时: {fudai_search_elapsed:.3f}s" + ) + elapsed = time.time() - start_time + analyser._log_kv( + "流程", + "run_once_basic完成(处理直播间)", + elapsed_seconds=round(elapsed, 2), + ) + + def handle_lottery_result_stage(analyser, start_time: float) -> None: """run_once_basic stage == "FUDai_RESULT" 分支: