From c9a07cc91ee266b1c2c76663cfc348ec4c5312cc Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 11:12:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20run=5Fonce=5Fbas?= =?UTF-8?q?ic=20=E4=B8=AD"IN=5FLIVE=5FROOM"=E5=88=86=E6=94=AF=E5=88=B0=20h?= =?UTF-8?q?andle=5Fin=5Flive=5Froom=5Fstage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将"在直播间"阶段的处理逻辑(约 44 行)抽到 fudai_detail_helpers.handle_in_live_room_stage。逻辑: - 如果刚切换直播间(_just_switched_room=True),等待福袋加载 (switch_room_wait_after_stage_diag_seconds 秒) - 调用 _handle_live_room_has_or_not_fudai 寻找福袋图标 - 写完成日志 douyin_fudai.py: 3071 → 3042 行 (-29) fudai_detail_helpers.py: 572 → 618 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 37 ++------------- .../fudai_modules/fudai_detail_helpers.py | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 33 deletions(-) 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" 分支: