diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 03fdad8..dd0c536 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1483,51 +1483,12 @@ class fudai_analyse: pass # 检查是否刚刚记录了预约,如果是,强制切换直播间,避免在同一直播间循环 - try: - just_recorded = getattr(self, "_just_recorded_reservation", False) - if just_recorded: - self._just_recorded_reservation = False # 清除标志 - try: - self._log_kv( - "预约", - "[预约] 刚刚记录预约,继续在新直播间搜索福袋", - ) - except Exception: - pass - try: - needswitch_cfg = bool(getattr(self, "needswitch", True)) - except Exception: - needswitch_cfg = True - if needswitch_cfg: - try: - self.swipe_up_to_next_live() - except Exception as exc: - try: - self._log_kv( - "预约", - "[预约] 执行上滑切换失败", - error=str(exc), - error_type=type(exc).__name__, - ) - except Exception: - pass - else: - try: - self._log_kv( - "预约", - "[预约] just_recorded_reservation 触发,但 needswitch=False,未切换", - ) - except Exception: - pass - elapsed = time.time() - start_time - self._log_kv( - "流程", - "run_once_basic完成(记录预约后切换直播间)", - elapsed_seconds=round(elapsed, 2), - ) - return - except Exception: - pass + from douyin.core.fudai_modules.fudai_detail_helpers import ( + try_just_recorded_reservation_switch, + ) + + if try_just_recorded_reservation_switch(self, start_time): + return # 预约检查耗时记录 reservation_elapsed = time.time() - reservation_check_start diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 334e738..ecc8340 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,65 @@ def log_screenshot_failed( pass +def try_just_recorded_reservation_switch(analyser, start_time: float) -> bool: + """run_once_basic 步骤:检查是否刚刚记录了预约,如果是则强制切换直播间。 + + 返回: + True:刚记录预约,已尝试切换并写完成日志(调用方应直接 return) + False:未触发,调用方继续正常流程 + """ + try: + just_recorded = getattr(analyser, "_just_recorded_reservation", False) + if not just_recorded: + return False + + analyser._just_recorded_reservation = False # 清除标志 + try: + analyser._log_kv( + "预约", + "[预约] 刚刚记录预约,继续在新直播间搜索福袋", + ) + except Exception: + pass + + try: + needswitch_cfg = bool(getattr(analyser, "needswitch", True)) + except Exception: + needswitch_cfg = True + + if needswitch_cfg: + try: + analyser.swipe_up_to_next_live() + except Exception as exc: + try: + analyser._log_kv( + "预约", + "[预约] 执行上滑切换失败", + error=str(exc), + error_type=type(exc).__name__, + ) + except Exception: + pass + else: + try: + analyser._log_kv( + "预约", + "[预约] just_recorded_reservation 触发,但 needswitch=False,未切换", + ) + except Exception: + pass + + elapsed = time.time() - start_time + analyser._log_kv( + "流程", + "run_once_basic完成(记录预约后切换直播间)", + elapsed_seconds=round(elapsed, 2), + ) + return True + except Exception: + return False + + def handle_coupon_popup(analyser, start_time: float) -> None: """run_once_basic stage == "COUPON_POPUP" 分支:按返回键关闭优惠券弹窗。""" analyser._log_kv("弹窗处理", "检测到优惠券弹窗,按返回键关闭")