fix fansclub recheck and countdown fallback

This commit is contained in:
Your Name committed 2026-06-23 22:00:31 +08:00
1 parent 33c6f7a54f
commit ed0aca5f28
7 files changed
+48 -14

No files matched your search

@@ -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,
@@ -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()
@@ -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
+3 -3
View File
@@ -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,
+7 -4
View File
@@ -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)
]
+6
View File
@@ -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,
@@ -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