From ed0aca5f289aba0096664acd812424ad3b8823e1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 23 Jun 2026 22:00:31 +0800 Subject: [PATCH] fix fansclub recheck and countdown fallback --- .../fudai_attend_pkg/fansclub_recovery.py | 11 +++++---- .../read_once.py | 2 +- .../read_with_retries.py | 2 +- douyin/fudai/douyin_fudai_contain_impl.py | 6 ++--- tests/test_fansclub_handler.py | 11 +++++---- tests/test_fudai_detail_ui_v2.py | 6 +++++ .../test_read_with_retries_countdown_guard.py | 24 +++++++++++++++++++ 7 files changed, 48 insertions(+), 14 deletions(-) diff --git a/douyin/fudai/core/fudai_attend_pkg/fansclub_recovery.py b/douyin/fudai/core/fudai_attend_pkg/fansclub_recovery.py index 64aacb3..59c2477 100644 --- a/douyin/fudai/core/fudai_attend_pkg/fansclub_recovery.py +++ b/douyin/fudai/core/fudai_attend_pkg/fansclub_recovery.py @@ -6,7 +6,6 @@ import os from typing import Any from douyin.fudai.core.coords import ( - DETAIL_OUTSIDE_CLICK, FANSCLUB_JOIN_CLICK, FANSCLUB_JOIN_FALLBACK_CLICK, ) @@ -32,23 +31,25 @@ def recover_to_fudai_detail_after_fansclub( if st == "FUDai_DETAIL": try: - analyser.click(*DETAIL_OUTSIDE_CLICK) + analyser._fansclub_joined_detail_recheck_pending = True analyser._log_kv( "参与", - "粉丝团加入后仍在详情页,先退出详情后继续寻找福袋", + "粉丝团加入后仍在详情页,保留详情页等待重新读取阈值后再决策", stage=st, seen=seen, attempt=i + 1, - action="close_detail_after_fansclub", + action="keep_detail_for_recheck_after_fansclub", ) except Exception: pass return False if st in ("IN_LIVE_ROOM", "LIVE_OR_UNKNOWN"): try: + analyser._fansclub_joined_detail_recheck_pending = True + analyser._skip_stage_diagnosis_and_find_fudai = True analyser._log_kv( "参与", - "粉丝团加入后回到直播间,继续寻找福袋", + "粉丝团加入后回到直播间,下一轮优先重新打开福袋详情并按阈值决策", stage=st, seen=seen, attempt=i + 1, diff --git a/douyin/fudai/core/fudai_detail_orchestrator_pkg/read_once.py b/douyin/fudai/core/fudai_detail_orchestrator_pkg/read_once.py index 31509ff..50f9944 100644 --- a/douyin/fudai/core/fudai_detail_orchestrator_pkg/read_once.py +++ b/douyin/fudai/core/fudai_detail_orchestrator_pkg/read_once.py @@ -517,7 +517,7 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]: # 解析倒计时 -> (剩余秒数, 未来时间戳) countdown_start = time.time() - countdown_end = countdown_start + 60.0 + countdown_end = countdown_start total_seconds_from_ocr = None # 保存OCR识别到的原始秒数 try: _cd0 = time.time() diff --git a/douyin/fudai/core/fudai_detail_orchestrator_pkg/read_with_retries.py b/douyin/fudai/core/fudai_detail_orchestrator_pkg/read_with_retries.py index 87ad4b7..5dfa50a 100644 --- a/douyin/fudai/core/fudai_detail_orchestrator_pkg/read_with_retries.py +++ b/douyin/fudai/core/fudai_detail_orchestrator_pkg/read_with_retries.py @@ -308,7 +308,7 @@ def read_fudai_detail_with_retries( if last_tuple is None: now = time.time() - last_tuple = ("", "", 0, 0, 0.0, (now, now + 60.0)) + last_tuple = ("", "", 0, 0, 0.0, (now, now, None)) content, time_text, participants, copies, prize_value_yuan, cd = last_tuple cd_start, cd_end = None, None diff --git a/douyin/fudai/douyin_fudai_contain_impl.py b/douyin/fudai/douyin_fudai_contain_impl.py index b5f14fd..86ea5ef 100644 --- a/douyin/fudai/douyin_fudai_contain_impl.py +++ b/douyin/fudai/douyin_fudai_contain_impl.py @@ -1106,7 +1106,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo room_title_hint=str(live_room_title_text_raw or live_room_title_raw or ""), ) mm_full, ss_full = _parse_mmss_from_full_text(countdown_full_raw) - if countdown_full_ocr_in_critical_path and mm_full and ss_full: + if mm_full and ss_full: countdown_mm_raw, countdown_ss_raw = mm_full, ss_full if _detail_verbose_logs(analyser): try: @@ -1119,7 +1119,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo ) except Exception: pass - elif renwu == 1 and info_line_raw: + if renwu == 1 and info_line_raw: mm_line, ss_line = _parse_mmss_from_full_text(info_line_raw) if mm_line and ss_line: countdown_mm_raw, countdown_ss_raw = mm_line, ss_line @@ -1260,7 +1260,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo room_title_hint=str(live_room_title_text_raw or live_room_title_raw or ""), ) mm_full_h, ss_full_h = _parse_mmss_from_full_text(countdown_full_raw) - if countdown_full_ocr_in_critical_path and mm_full_h and ss_full_h: + if mm_full_h and ss_full_h: countdown_mm_raw, countdown_ss_raw = mm_full_h, ss_full_h countdown_mm_raw, countdown_ss_raw = _apply_countdown_text_fallback( analyser, diff --git a/tests/test_fansclub_handler.py b/tests/test_fansclub_handler.py index f358bda..759598f 100644 --- a/tests/test_fansclub_handler.py +++ b/tests/test_fansclub_handler.py @@ -4,7 +4,7 @@ - handle_fansclub_branch 会处理粉丝团门槛并返回是否已经参与 - 设置 analyser.last_attend_fail_reason = "fansclub_required" - 在路径上点击参与按钮 (543, 2070) -- 普通粉丝团加入后不伪造参与成功;若仍在详情页,先退出详情再继续找福袋 +- 普通粉丝团加入后不伪造参与成功;若仍在详情页,保留详情重新读详情/阈值 - 异常路径不抛 """ from __future__ import annotations @@ -74,14 +74,15 @@ class TestHandleFansclubBranch: ] assert len(attend_calls) >= 1 - def test_closes_detail_after_recovery_confirms_still_on_detail(self): - """普通粉丝团路径不算参与成功;若仍在详情页,先退出详情再继续找福袋。""" + def test_keeps_detail_after_recovery_confirms_still_on_detail(self): + """普通粉丝团路径不算参与成功;若仍在详情页,留给下一轮重新读详情/阈值。""" a = _mk_analyser() handle_fansclub_branch(a, "加入粉丝团") close_calls = [ c for c in a.click.call_args_list if c.args == (500, 470) ] - assert len(close_calls) == 1 + assert close_calls == [] + assert a._fansclub_joined_detail_recheck_pending is True def test_does_not_mark_success_when_recovery_sees_detail_page(self): a = _mk_analyser() @@ -96,6 +97,8 @@ class TestHandleFansclubBranch: result = handle_fansclub_branch(a, "加入粉丝团") assert result is False + assert a._fansclub_joined_detail_recheck_pending is True + assert a._skip_stage_diagnosis_and_find_fudai is True close_calls = [ c for c in a.click.call_args_list if c.args == (500, 470) ] diff --git a/tests/test_fudai_detail_ui_v2.py b/tests/test_fudai_detail_ui_v2.py index e9ffe3d..49ec503 100644 --- a/tests/test_fudai_detail_ui_v2.py +++ b/tests/test_fudai_detail_ui_v2.py @@ -393,6 +393,12 @@ def test_countdown_text_fallback_uses_existing_ocr_without_extra_ocr(): assert (mm, ss) == ("00", "00") +def test_countdown_full_result_can_override_split_when_scheduled(): + from douyin.fudai.douyin_fudai_contain_impl import _parse_mmss_from_full_text + + assert _parse_mmss_from_full_text("45秒后开奖") == ("00", "45") + + def test_info_line_ocr_is_not_in_detail_critical_path_by_default(monkeypatch): from douyin.fudai.douyin_fudai_contain_impl import ( _should_schedule_info_line_ocr, diff --git a/tests/test_read_with_retries_countdown_guard.py b/tests/test_read_with_retries_countdown_guard.py index add4b1e..6414faf 100644 --- a/tests/test_read_with_retries_countdown_guard.py +++ b/tests/test_read_with_retries_countdown_guard.py @@ -60,3 +60,27 @@ def test_invalid_countdown_text_is_rejected_by_filter_layer(): skip, reason = should_skip_fudai_by_config(analyser, detail) assert skip is True assert reason == "countdown_invalid" + + +def test_missing_countdown_text_does_not_log_default_sixty_seconds(): + analyser = _mk_analyser() + now = time.time() + only_tuple = ("福袋", "", 10, 1, 999.0, (now, now, None)) + + with patch( + "douyin.fudai.core.fudai_detail_orchestrator_pkg.read_with_retries.read_fudai_detail_once", + return_value=("ok", only_tuple, {}), + ), patch( + "douyin.fudai.core.fudai_detail_orchestrator_pkg.read_with_retries.validate_fudai_detail", + return_value=(True, "ok"), + ): + read_fudai_detail_with_retries( + analyser=analyser, + fudai_x=0, + read_once_callback=None, + close_detail_callback=None, + ensure_open_callback=None, + ) + + log_text = "\n".join(str(c) for c in analyser._log_kv.call_args_list) + assert "倒计时=未识别,剩余59秒" not in log_text