diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 41ac1c2..ed9d584 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -410,37 +410,12 @@ class fudai_analyse: return # 0.1. 若启用高价值预约:先处理"是否需要回退到预约直播间" - try: - reservation_check_start = time.time() - self._log_kv("预约", "开始预约检查", timestamp=reservation_check_start) + from douyin.core.fudai_modules.fudai_detail_helpers import ( + run_reservation_check_block, + ) - # 初始化预约队列(第一次运行时清空 + 写状态文件) - from douyin.core.fudai_modules.fudai_detail_helpers import ( - initialize_reservations_queue, - ) - - initialize_reservations_queue(self) - - high_value_enabled = getattr(self, "high_value_fudai_enabled", False) - reservations_list = getattr(self, "reservations", None) - reservations_count = len(reservations_list) if reservations_list else 0 - - # 添加详细的调试日志,确认预约回退逻辑的触发条件 - from douyin.core.fudai_modules.fudai_detail_helpers import ( - log_reservation_check_status, - ) - - log_reservation_check_status(self, high_value_enabled) - - if high_value_enabled and reservations_list: - from douyin.core.fudai_modules.fudai_detail_helpers import ( - process_high_value_reservation_check, - ) - - if process_high_value_reservation_check(self, start_time): - return - except Exception: - pass + if run_reservation_check_block(self, start_time): + return # 检查是否刚刚记录了预约,如果是,强制切换直播间,避免在同一直播间循环 from douyin.core.fudai_modules.fudai_detail_helpers import ( @@ -450,10 +425,6 @@ class fudai_analyse: if try_just_recorded_reservation_switch(self, start_time): return - # 预约检查耗时记录 - reservation_elapsed = time.time() - reservation_check_start - self._log_kv("预约", f"预约检查完成,耗时: {reservation_elapsed:.3f}s") - # 0.5. 检查是否需要跳过阶段检测,直接查找福袋(点击参与抽奖后) from douyin.core.fudai_modules.fudai_detail_helpers import ( try_skip_stage_diagnosis, diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 47e98c0..59f1dec 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -273,6 +273,44 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N ) +def run_reservation_check_block(analyser, start_time: float) -> bool: + """run_once_basic 步骤 0.1:完整的预约检查块。 + + 流程: + 1. 写"开始预约检查"日志 + 2. initialize_reservations_queue + 3. log_reservation_check_status + 4. 如启用高价值 + 有预约队列 → process_high_value_reservation_check + + 返回: + True:触发了早返回(队列满等待 / 所有预约完成重置),调用方应直接 return + False:未触发早返回,调用方继续 + """ + try: + reservation_check_start = time.time() + analyser._log_kv("预约", "开始预约检查", timestamp=reservation_check_start) + + initialize_reservations_queue(analyser) + + high_value_enabled = getattr(analyser, "high_value_fudai_enabled", False) + reservations_list = getattr(analyser, "reservations", None) + + log_reservation_check_status(analyser, high_value_enabled) + + if high_value_enabled and reservations_list: + if process_high_value_reservation_check(analyser, start_time): + return True + + # 预约检查耗时记录 + reservation_elapsed = time.time() - reservation_check_start + analyser._log_kv( + "预约", f"预约检查完成,耗时: {reservation_elapsed:.3f}s" + ) + except Exception: + pass + return False + + def step1_or_step2_dispatcher(analyser, start_time: float): """步骤1(第二次打开)vs 步骤2(第一次打开)的分发。