fix countdown digit extraction regression

This commit is contained in:
Your Name committed 2026-06-23 19:05:07 +08:00
1 parent 7086ab1d6e
commit ab664e4da8
1 file changed
+4 -4
@@ -9,6 +9,10 @@ def extract_countdown_digits(text: str, max_digits: int = 2) -> str:
normalized = raw.translate(str.maketrans({"O": "0", "o": "0", "U": "0", "u": "0"}))
digits = "".join(ch for ch in normalized if ch.isdigit())
if len(digits) > max_digits:
candidate = digits[:max_digits]
if set(candidate) == {"0"} and digits.lstrip("0"):
actual = digits.lstrip("0")[:max_digits]
return actual.zfill(max_digits)
# 倒计时分钟/秒区域偶发会混入噪声数字(如 "601"、"0123")。
# 对 2 位提取场景,优先尝试滑窗中第一个“合法”候选(00~59),
# 若都不合法再回退到原有左侧截取策略。
@@ -21,10 +25,6 @@ def extract_countdown_digits(text: str, max_digits: int = 2) -> str:
continue
if 0 <= v <= 59:
return win
candidate = digits[:max_digits]
if set(candidate) == {"0"} and digits.lstrip("0"):
actual = digits.lstrip("0")[:max_digits]
return actual.zfill(max_digits)
return candidate
if len(digits) == 1:
return "0" + digits