fix(ingest): raise ref cap to 50 and clarify invalid bvid error

This commit is contained in:
kairee committed 2026-11-01 15:05:17 +08:00
1 parent b5bf7d9b8f
commit b0c53e8a2f
7 files changed
+107 -9

No files matched your search

+3
View File
@@ -80,6 +80,9 @@ def format_manual_reply(manual_result: Any) -> str:
return "未识别到 B 站视频引用,请发送视频链接或 BV 号,例如 BV1x8x166EzY。"
results = list(getattr(manual_result, "results", []) or [])
lines = [_result_line(item) for item in results]
truncated = int(getattr(manual_result, "truncated", 0) or 0)
if truncated > 0:
lines.append(f"⚠️ 本消息还有 {truncated} 个引用未处理,请分批再发一次。")
header = f"共识别 {refs} 个引用,入库 {int(getattr(manual_result, 'added', 0) or 0)} 条:"
return "\n".join([header, *lines])
+25 -5
View File
@@ -11,7 +11,11 @@ import time
from dataclasses import dataclass, field
from typing import Any
from ..bilibili.client import BilibiliError, BilibiliProtocolError
from ..bilibili.client import (
BilibiliAPIError,
BilibiliError,
BilibiliProtocolError,
)
from ..config import ConfigStore
from ..repository import Repository
from ..timeutil import shanghai_date
@@ -42,6 +46,7 @@ class IngestResult:
class ManualIngestResult:
refs: int = 0
added: int = 0
truncated: int = 0
results: list[IngestResult] = field(default_factory=list)
@property
@@ -52,6 +57,7 @@ class ManualIngestResult:
return {
"refs": self.refs,
"added": self.added,
"truncated": self.truncated,
"ok": self.ok,
"results": [result.as_dict() for result in self.results],
}
@@ -180,16 +186,30 @@ class LibraryService:
# ------------------------------------------------------------ manual
def ingest_text(self, text: object) -> ManualIngestResult:
refs = extract_video_refs(text, limit=self.max_refs)
result = ManualIngestResult(refs=len(refs))
if not refs:
all_refs = extract_video_refs(text, limit=None)
result = ManualIngestResult(refs=len(all_refs))
if not all_refs:
return result
if len(all_refs) > self.max_refs:
result.truncated = len(all_refs) - self.max_refs
all_refs = all_refs[: self.max_refs]
result.refs = len(all_refs)
client = self.read_provider.get()
ups: list[tuple[int | None, str]] = []
for ref in refs:
for ref in all_refs:
try:
detail = self._resolve_ref(client, ref)
except BilibiliAPIError as exc:
message = (
"无法解析该视频引用:BV 号/av 号无效或视频不存在(code=-400)"
if exc.code == -400 else str(exc)
)
result.results.append(IngestResult(
ok=False, aid=None, state="error", message=message,
))
self._log("warning", "ingest.manual_failed", error=str(exc))
continue
except BilibiliError as exc:
result.results.append(IngestResult(
ok=False, aid=None, state="error", message=str(exc),
+2 -1
View File
@@ -25,7 +25,8 @@ _AID_RE = re.compile(r"(?<![0-9A-Za-z])av(\d{1,20})(?![0-9A-Za-z])", re.IGNORECA
_SHORT_RE = re.compile(r"b23\.tv/([0-9A-Za-z]+)")
# 单条消息最多处理的引用数,避免误粘贴一段文本导致突发请求。
DEFAULT_MAX_REFS = 10
# 15 个 BV 号批量测试手动入库是常见用法,上限放宽到 50,超出时回执会提示分批发送。
DEFAULT_MAX_REFS = 50
@dataclass(frozen=True)