feat(ingest): db-only library ingest and telegram manual ingest
This commit is contained in:
1 parent
d2adb65e08
commit
62abbd7ea1
6 files changed
+866
-28
No files matched your search
@@ -53,6 +53,43 @@ def format_duration(seconds: int) -> str:
|
||||
return f"{minutes}:{secs:02d}"
|
||||
|
||||
|
||||
def _result_line(result: Any) -> str:
|
||||
state = getattr(result, "state", "")
|
||||
title = html.escape(str(getattr(result, "title", "") or ""))
|
||||
message = str(getattr(result, "message", "") or "")
|
||||
aid = getattr(result, "aid", None)
|
||||
suffix = f"《{title}》" if title else ""
|
||||
ref = f"(aid {aid})" if aid else ""
|
||||
icon = {
|
||||
"added": "✅", "recovered": "♻️", "exists": "ℹ️",
|
||||
"error": "⚠️", "missing": "❔",
|
||||
}.get(state, "•")
|
||||
body = message or "完成"
|
||||
return f"{icon} {body}{suffix}{ref}".strip()
|
||||
|
||||
|
||||
def format_ingest_result(result: Any) -> str:
|
||||
"""候选确认后的回执(候选确认 / 手动入库单条)。"""
|
||||
return _result_line(result)
|
||||
|
||||
|
||||
def format_manual_reply(manual_result: Any) -> str:
|
||||
"""私聊文本手动入库的汇总回执。"""
|
||||
refs = int(getattr(manual_result, "refs", 0) or 0)
|
||||
if refs <= 0:
|
||||
return "未识别到 B 站视频引用,请发送视频链接或 BV 号,例如 BV1x8x166EzY。"
|
||||
results = list(getattr(manual_result, "results", []) or [])
|
||||
lines = [_result_line(item) for item in results]
|
||||
header = f"共识别 {refs} 个引用,入库 {int(getattr(manual_result, 'added', 0) or 0)} 条:"
|
||||
return "\n".join([header, *lines])
|
||||
|
||||
|
||||
HELP_TEXT = (
|
||||
"发送 B 站视频链接、BV 号或 av 号即可手动入库并开始追踪。\n"
|
||||
"例如:https://www.bilibili.com/video/BV1x8x166EzY 或 BV1x8x166EzY"
|
||||
)
|
||||
|
||||
|
||||
def format_candidate(candidate: Mapping[str, Any]) -> str:
|
||||
title = html.escape(str(candidate.get("title") or "(无标题)"))
|
||||
up_name = html.escape(str(candidate.get("up_name") or "未知UP"))
|
||||
@@ -184,7 +221,7 @@ class TelegramClient:
|
||||
keyboard = {
|
||||
"inline_keyboard": [
|
||||
[
|
||||
{"text": "⭐ 收藏", "callback_data": f"fav:{candidate['aid']}"},
|
||||
{"text": "📥 入库", "callback_data": f"add:{candidate['aid']}"},
|
||||
{"text": "🙈 忽略", "callback_data": f"ign:{candidate['aid']}"},
|
||||
{"text": "🚫 拉黑", "callback_data": f"blk:{candidate['aid']}"},
|
||||
]
|
||||
@@ -199,7 +236,7 @@ class TelegramClient:
|
||||
) -> list[dict[str, Any]]:
|
||||
params: dict[str, Any] = {
|
||||
"timeout": self.poll_timeout if timeout is None else int(timeout),
|
||||
"allowed_updates": json.dumps(["callback_query"]),
|
||||
"allowed_updates": json.dumps(["callback_query", "message"]),
|
||||
}
|
||||
if offset is not None:
|
||||
params["offset"] = int(offset)
|
||||
|
||||
Reference in new issue
Block a user