From d9323f2012a355924fdf0e49d8d48a3948153cf1 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 12:30:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20run=5Fonce=5Fbas?= =?UTF-8?q?ic=20=E5=85=A5=E5=8F=A3"=E8=AE=B0=E5=BD=95=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E9=97=B4=E6=A0=87=E9=A2=98"=E5=9D=97=E5=88=B0=20record=5Froom?= =?UTF-8?q?=5Ftitle=5Fif=5Fnot=5Fjust=5Fswitched?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 run_once_basic 入口的"记录直播间标题"块(约 14 行)抽到 helper: - 检查 _just_switched_room 标志 - 未刚切换时调用 _record_room_title_and_pos - 刚切换时写"跳过重复记录"日志 douyin_fudai.py: 1412 → 1404 行 (-8) fudai_detail_helpers.py: 2640 → 2659 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 20 ++++++------------- .../fudai_modules/fudai_detail_helpers.py | 19 ++++++++++++++++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index b3e92ca..0479c34 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -692,20 +692,12 @@ class fudai_analyse: except Exception: pass - # 尝试记录当前直播间的标题与位置,确保所有直播间(不限福袋)都被采集到运行时映射表 - # 但如果刚刚切换直播间,避免重复记录(切换前已记录) - try: - just_switched = getattr(self, "_just_switched_room", False) - if not just_switched: - self._record_room_title_and_pos() - else: - self._log_kv( - "预约", - "[预约] 刚刚切换直播间,跳过重复记录标题", - reason="avoid_duplicate_after_switch", - ) - except Exception: - pass + # 尝试记录当前直播间的标题与位置(如果刚切换则跳过重复记录) + from douyin.core.fudai_modules.fudai_detail_helpers import ( + record_room_title_if_not_just_switched, + ) + + record_room_title_if_not_just_switched(self) # 直接参与标志已移除,相关旧逻辑已清理,继续按正常流程执行 # 0. 如果正在等待开奖:不在此期间检查并抢占其他预约,避免放弃当前正在参加的直播间 diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index be6386f..116b84f 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,25 @@ def log_screenshot_failed( pass +def record_room_title_if_not_just_switched(analyser) -> None: + """run_once_basic 入口:尝试记录当前直播间的标题与位置。 + + 如果刚切换直播间(_just_switched_room=True),跳过重复记录(切换前已记录)。 + """ + try: + just_switched = getattr(analyser, "_just_switched_room", False) + if not just_switched: + analyser._record_room_title_and_pos() + else: + analyser._log_kv( + "预约", + "[预约] 刚刚切换直播间,跳过重复记录标题", + reason="avoid_duplicate_after_switch", + ) + except Exception: + pass + + def dispatch_last_fudai_detail_status(analyser, start_time: float) -> bool: """_handle_in_fudai_detail 中根据 _last_fudai_detail_status 分发到对应处理 helper。