From 4af2adc4d61f054bc515e64159488918c7e4e3f6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 23 Jun 2026 11:22:23 +0800 Subject: [PATCH] fix: preserve fudai detail countdown detection --- douyin/fudai/core/coords.py | 2 +- douyin/fudai/douyin_fudai_contain_impl.py | 61 +++++++++++++++++++++++ tests/test_fudai_detail_ui_v2.py | 23 +++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/douyin/fudai/core/coords.py b/douyin/fudai/core/coords.py index 6ec985f..04898b7 100644 --- a/douyin/fudai/core/coords.py +++ b/douyin/fudai/core/coords.py @@ -211,7 +211,7 @@ def _apply_region_overrides(defaults: dict[str, Any], overrides: Any) -> dict[st parsed = _tuple4(candidate) if parsed is not None: merged[key] = parsed - else: + elif key in overrides and candidate is not None: merged[key] = candidate return merged diff --git a/douyin/fudai/douyin_fudai_contain_impl.py b/douyin/fudai/douyin_fudai_contain_impl.py index ec57eb0..55b40b2 100644 --- a/douyin/fudai/douyin_fudai_contain_impl.py +++ b/douyin/fudai/douyin_fudai_contain_impl.py @@ -537,6 +537,36 @@ def _normalize_countdown_pair(mm_raw: Any, ss_raw: Any) -> Tuple[str, str]: return "", "" +def _apply_countdown_text_fallback( + analyser: Any, + countdown_mm_raw: Any, + countdown_ss_raw: Any, + sources: Tuple[Tuple[str, Any], ...], +) -> Tuple[Any, Any]: + """Use already-recognized text as a cheap countdown fallback before extra OCR.""" + mm_norm, ss_norm = _normalize_countdown_pair(countdown_mm_raw, countdown_ss_raw) + if mm_norm and ss_norm: + return countdown_mm_raw, countdown_ss_raw + for source_name, source_text in sources: + mm_text, ss_text = _parse_mmss_from_full_text(source_text) + if not (mm_text and ss_text): + continue + if _detail_verbose_logs(analyser): + try: + analyser._log_kv( + "倒计时", + "已有OCR文本命中倒计时fallback", + source=source_name, + text=str(source_text or "")[:80], + mm=mm_text, + ss=ss_text, + ) + except Exception: + pass + return mm_text, ss_text + return countdown_mm_raw, countdown_ss_raw + + def _select_countdown_from_candidates( analyser: Any, candidate_meta: List[Dict[str, Any]], @@ -1100,6 +1130,17 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo ) except Exception: pass + countdown_mm_raw, countdown_ss_raw = _apply_countdown_text_fallback( + analyser, + countdown_mm_raw, + countdown_ss_raw, + ( + ("content", fudai_content_raw), + ("value", value_raw), + ("info_line", info_line_raw), + ("countdown_full", countdown_full_raw), + ), + ) if picked: picked_idx = int(picked.get("idx", -1)) if _detail_verbose_logs(analyser): @@ -1219,6 +1260,16 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo 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: countdown_mm_raw, countdown_ss_raw = mm_full_h, ss_full_h + countdown_mm_raw, countdown_ss_raw = _apply_countdown_text_fallback( + analyser, + countdown_mm_raw, + countdown_ss_raw, + ( + ("content", fudai_content_raw), + ("value", value_raw), + ("countdown_full", countdown_full_raw), + ), + ) if picked_heavy: picked_heavy_idx = int(picked_heavy.get("idx", -1)) if _detail_verbose_logs(analyser): @@ -1487,6 +1538,16 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo mm_fb, ss_fb = _parse_mmss_from_full_text(countdown_full_raw_fb) if countdown_full_ocr_in_critical_path and mm_fb and ss_fb: countdown_mm_raw, countdown_ss_raw = mm_fb, ss_fb + countdown_mm_raw, countdown_ss_raw = _apply_countdown_text_fallback( + analyser, + countdown_mm_raw, + countdown_ss_raw, + ( + ("content", fudai_content_raw), + ("value", value_raw), + ("countdown_full", countdown_full_raw_fb), + ), + ) if picked_fb: picked_fb_idx = int(picked_fb.get("idx", -1)) if _detail_verbose_logs(analyser): diff --git a/tests/test_fudai_detail_ui_v2.py b/tests/test_fudai_detail_ui_v2.py index a2c4b66..18da7b0 100644 --- a/tests/test_fudai_detail_ui_v2.py +++ b/tests/test_fudai_detail_ui_v2.py @@ -79,6 +79,9 @@ def test_detail_profile_prefers_config_overrides(monkeypatch): assert legacy["button"] == (101, 202, 303, 404) assert v2_two["content"] == (1, 2, 3, 4) + assert v2_two["version"] == "v2_0" + assert v2_one["version"] == "v2_0" + assert legacy["version"] == "legacy" assert v2_one["info_line"] == (11, 22, 33, 44) assert lottery["pixel"] == (7, 8, 9, 10) assert lottery["click"] == (66, 77) @@ -350,6 +353,26 @@ def test_countdown_full_ocr_critical_path_requires_explicit_opt_in(monkeypatch): assert _should_schedule_countdown_full_ocr(analyser, disabled_switches) is False +def test_countdown_text_fallback_uses_existing_ocr_without_extra_ocr(): + from douyin.fudai.douyin_fudai_contain_impl import ( + _apply_countdown_text_fallback, + ) + + analyser = SimpleNamespace(fudai_detail_verbose_logs=False) + + mm, ss = _apply_countdown_text_fallback( + analyser, + "", + "", + ( + ("content", "免费购129人已参与00 : 00后开奖"), + ("value", ""), + ), + ) + + assert (mm, ss) == ("00", "00") + + 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,