From 78e53603d30640d862b0ec2f213ac8629b4da3c7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 16 Jan 2026 02:18:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BC=80=E5=A5=96?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4=E6=88=B3=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=8F=82=E4=B8=8E=E9=80=BB=E8=BE=91=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/core/douyin_fudai.py | 36 ++++++------------- douyin/fudai/core/fudai_attend.py | 2 ++ douyin/fudai/douyin_fudai_core.py | 2 ++ douyin/handlers/douyin_swipe_handler.py | 16 +++++++-- .../reservation/douyin_reservation_handler.py | 1 + 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index d477928..efcc9f8 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -344,6 +344,7 @@ class fudai_analyse: self._fudai_detail_consecutive_failures: int = 0 # 连续失败次数 self._detail_closed_by_attend: bool = False # 详情页是否由参与操作关闭 self._lottery_result_expected_ts: float = 0.0 # 开奖结果预期时间戳 + self._lottery_wait_start_ts: float = 0.0 # 开始等待开奖的时间戳 # 初次加载配置 self.load_config() @@ -1173,14 +1174,12 @@ class fudai_analyse: if getattr(self, "_waiting_for_lottery_result", False): wait_lottery_start = time.time() try: - # 在等待开奖期间只检测开奖结果,不触发预约抢占逻辑, + # 在等待开奖期间持续检测开奖结果,不触发预约抢占逻辑, # 以确保按顺序完成当前参与流程。 future_ts = getattr(self, "_lottery_result_expected_ts", 0.0) or 0.0 current_ts = time.time() - remain_seconds = max(0, future_ts - current_ts + 6.0) - # 开奖时间 + 1秒缓冲后开始检测开奖结果 - check_start_ts = future_ts + 1.0 + # 从设置等待标志后开始持续检测,最多等待开奖时间+10秒 timeout_ts = future_ts + 10.0 if current_ts >= timeout_ts: @@ -1193,15 +1192,17 @@ class fudai_analyse: 超时秒数=timeout_seconds, 等待开奖总耗时=round(time.time() - wait_lottery_start, 2), ) - elif current_ts >= check_start_ts: - passed_seconds = int(current_ts - future_ts) + else: + # 持续OCR检测开奖结果 + wait_start_ts = getattr(self, "_lottery_wait_start_ts", future_ts) + passed_seconds = int(current_ts - wait_start_ts) self._log_kv( "参与", - f"等待开奖结果中,进入连续检测窗口(最多10s),已过开奖时间{passed_seconds}秒", - 已过开奖时间秒数=passed_seconds, + f"等待开奖结果中,持续OCR检测,已等待{passed_seconds}秒", + 已等待秒数=passed_seconds, ) - deadline_ts = min(timeout_ts, check_start_ts + 10.0) + deadline_ts = timeout_ts attempt = 0 consecutive_none = 0 @@ -1325,22 +1326,6 @@ class fudai_analyse: except Exception: pass return - else: - wait_s = min(2.0, remain_seconds) - remain_seconds_int = int(remain_seconds) - self._log_kv( - "参与", - f"等待开奖中,剩余{remain_seconds_int}秒", - 剩余秒数=remain_seconds_int, - ) - self.operation.delay(wait_s) - elapsed = time.time() - start_time - self._log_kv( - "流程", - f"run_once_basic完成(等待开奖中,剩余{remain_seconds_int}秒)", - elapsed_seconds=round(elapsed, 2), - ) - return except Exception as exc: self._log_kv("参与", "等待开奖检测时出错", error=str(exc)) self._waiting_for_lottery_result = False @@ -3452,6 +3437,7 @@ class fudai_analyse: # 直接保存开奖时间戳,等待时直接用 future_timestamp - time.time() 计算剩余秒数 self._waiting_for_lottery_result = True self._lottery_result_expected_ts = future_timestamp + self._lottery_wait_start_ts = time.time() self._log_kv( "参与", diff --git a/douyin/fudai/core/fudai_attend.py b/douyin/fudai/core/fudai_attend.py index 2c409e8..eeb92b8 100644 --- a/douyin/fudai/core/fudai_attend.py +++ b/douyin/fudai/core/fudai_attend.py @@ -173,6 +173,7 @@ def attend_choujiang(analyser) -> bool: # 设置等待开奖标志和预期开奖时间 analyser._waiting_for_lottery_result = True analyser._lottery_result_expected_ts = future_ts + analyser._lottery_wait_start_ts = current_time analyser._log_kv( "参与", "参与成功,设置等待开奖标志", @@ -389,6 +390,7 @@ def attend_choujiang(analyser) -> bool: # 设置等待开奖标志和预期开奖时间 analyser._waiting_for_lottery_result = True analyser._lottery_result_expected_ts = future_ts + analyser._lottery_wait_start_ts = current_time # #region agent log - countdown set with open(get_debug_log_path(), "a", encoding="utf-8") as f: diff --git a/douyin/fudai/douyin_fudai_core.py b/douyin/fudai/douyin_fudai_core.py index 1068fc4..7e96c8e 100644 --- a/douyin/fudai/douyin_fudai_core.py +++ b/douyin/fudai/douyin_fudai_core.py @@ -2221,6 +2221,7 @@ def attend_choujiang(analyser) -> bool: # 设置等待开奖标志和预期开奖时间 analyser._waiting_for_lottery_result = True analyser._lottery_result_expected_ts = future_ts + analyser._lottery_wait_start_ts = current_time analyser._log_kv( "参与", "参与成功,设置等待开奖标志", @@ -2368,6 +2369,7 @@ def attend_choujiang(analyser) -> bool: # 设置等待开奖标志和预期开奖时间 analyser._waiting_for_lottery_result = True analyser._lottery_result_expected_ts = future_ts + analyser._lottery_wait_start_ts = current_time analyser._log_kv( "参与", "点击参与抽奖后,设置等待开奖标志", diff --git a/douyin/handlers/douyin_swipe_handler.py b/douyin/handlers/douyin_swipe_handler.py index 2d9c2da..04c4069 100644 --- a/douyin/handlers/douyin_swipe_handler.py +++ b/douyin/handlers/douyin_swipe_handler.py @@ -69,6 +69,17 @@ class SwipeHandler: pass start_time = time.time() + + # 在切换直播间前记录当前直播间的标题和位置到运行时映射表 + try: + skip_record = bool( + getattr(analyser, "_skip_record_title_during_seek", False) + ) + if not skip_record: + analyser._record_room_title_and_pos() # type: ignore[attr-defined] + except Exception: + pass + douyin_swipe_ops.swipe_up_switch_live(analyser) # 记录直播间位置:上滑 +1 try: @@ -108,14 +119,13 @@ class SwipeHandler: pass # 记录当前直播间的标题和位置到运行时映射表(用于回退校验) - # 如果是在回退过程中(_seek_reservation_room),跳过记录,因为之前已经记录过了 - # 切换直播间后跳过记录,因为切换前已记录,避免重复 + # 切换前已记录,这里跳过避免重复 try: skip_record = bool( getattr(analyser, "_skip_record_title_during_seek", False) ) if not skip_record: - # 由于刚刚切换,跳过记录以避免重复 + # 切换前已记录,跳过避免重复 pass except Exception: pass diff --git a/douyin/reservation/douyin_reservation_handler.py b/douyin/reservation/douyin_reservation_handler.py index c6eaee5..d6e41c1 100644 --- a/douyin/reservation/douyin_reservation_handler.py +++ b/douyin/reservation/douyin_reservation_handler.py @@ -781,6 +781,7 @@ class ReservationHandler: if remain_seconds > 0: analyser._waiting_for_lottery_result = True analyser._lottery_result_expected_ts = future_ts + analyser._lottery_wait_start_ts = current_time analyser._current_attending_reservation_fudai = ( True # 标记当前正在参与预约福袋 )