dbs-video-extract
Accepts short video links or shared text from Douyin, Xiaohongshu, WeChat Channels, etc., queries post/account metrics, extracts speech transcripts, and archives them as Markdown organized by author and title. Intended for users who want to fully parse short videos to obtain metrics or transcripts; runs a preflight check for TikHub and Qingdou credentials beforehand and guides beginners through purchasing and secure configuration if keys are missing.
1How It Works & Mechanism
Runs a read-only credential precheck before any extraction action, narrowing capabilities down to whichever side is currently available via credential_state.
python3 scripts/extract_video.py --check-keys
Maintains a clear division of labor between two external services: TikHub handles structured post/account metrics, while Qingdou handles voice transcripts, with hardcoded platform support scopes.
- 当前 TikHub 专用数据解析支持抖音、小红书和微信视频号;其他轻抖可识别的平台仍可只执行文字稿提取。
TikHub operations use MCP (Streamable HTTP), with protocol versions and endpoints for the three platforms hardcoded as script constants.
MCP_PROTOCOL_VERSION = "2024-11-05"
Qingdou operations follow a REST workflow of 'submit task + poll for results', with built-in timeout and interval controls.
url = f"{base_url.rstrip('/')}/web/api/getTaskResult?{query}"
Keys are resolved via a four-tier fallback order: environment variables → user-specified local file → ~/.config/dbs/API_Keys.md → macOS Keychain.
["security", "find-generic-password", "-s", KEYCHAIN_SERVICE, "-w"],
The bundled secure configuration script uses getpass for hidden input, writes to a file with 0600 permissions, and performs atomic replacement so keys never appear in commands, responses, or logs.
secret = getpass.getpass("使用凭证:").strip()
Request failure messages replace API keys with [REDACTED] before throwing errors to prevent credentials from leaking into responses via error messages.
detail = detail.replace(api_key, "[REDACTED]")
Performs shape validation on the Base URL and API paths (permitting only pure HTTPS domains + a fixed /api/v1/ prefix) to minimize the attack surface of redirected destinations.
raise TikHubError("Base URL 必须是只有域名的 HTTPS 地址。")
Archiving rules and user edit protection: writes to {output_dir}/{author}/{title}.md, skips existing files by default, and only overwrites when --overwrite is set.
path.write_text(render_markdown(item, title, author), encoding="utf-8")
When credentials are missing, avoids throwing technical jargon and instead follows a smooth path: 'Explain API Key → Select Capabilities → Purchase Guidance → Mandatory Legal Notice → Local Secure Configuration'.
> dbskill 是免费开源项目,与 TikHub、轻抖无隶属、合作或利益关系。充值由用户自主决定,相关交易、服务、争议及风险由用户自行承担;法律另有规定的除外,dbskill 不承担责任。
Preserves partial results on single-sided failures: if either side fails, the other side still completes, and partial_success is marked in the JSON summary.
TikHub 或轻抖任一侧失败时继续完成另一侧,并在汇总中标记 `partial_success`。已经取得的结果不能因单侧失败而丢弃。
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| api | TikHub(作品/账号数据,MCP Streamable HTTP + REST) |
| api | 轻抖(语音文字稿提交与轮询) |
| cli | python3(运行 4 个自带脚本;仅标准库) |
| cli | security(macOS 钥匙串读取,仅 darwin 且未禁用时) |
| network | 购买/充值页(仅展示给用户人工操作,不由脚本访问) |
4Recommended Governance & Evidence
- 本地凭据 / 浏览器配置: Reads user login cookies/sessions/keyrings: macOS Keychain services dbs-tikhub-api-key / dbs-qingdou-api-key (security find-generic-
- scripts/: Executes local scripts or commands: python3 scripts/extract_video.py --check-keys / --mode both|data|transcript
- 网络端点: Declares external network access: TikHub: https://api.tikhub.dev / https://api.tikhub.io (REST)
- 本地工作目录: File I/O and artifact generation: {output_dir}/{author}/{title}.md (transcript archiving; skips existing files by default, overwrites only with --overwrite)
5Second-Pass Verification
- [ok] 凭证四级来源与钥匙串调用真实存在 — tikhub_api.py / extract_video_transcript.py 中 find_api_key 依次读 env → 指定文件 → ~/.config/dbs/API_Keys.md → subprocess security;KEYCHAIN_SERVICE 分别为 dbs-tikhub-api-key、dbs-qingdou-api-key。
- [ok] 凭证写入按安全实践(0600 + 原子替换) — configure_api_key.py:mkstemp → write → temporary.chmod(0o600) → os.replace → target.chmod(0o600),异常时 unlink 临时文件。
- [ok] 错误信息脱敏(不泄漏 Key) — 两个客户端均含 detail.replace(api_key, "[REDACTED]"),且响应体截断(500/1000 字符)。
- [ok] 外部端點清单无遗漏 — 全量 URL 抽取得到的运行时端點仅 TikHub(REST/MCP)与轻抖;其余为文档/购买页链接。
- [ok] 无第三方 Python 包依赖 — 脚本 import 仅 json/logging/os/re/subprocess/sys/time/urllib/datetime/pathlib/typing/argparse/tempfile/getpass;目录内无 requirements.txt/setup.py/pyproject.toml。
- [ok] 不绕过平台限制、不自动下载/发布 — SKILL.md 原文"公开、删除、私密、版权和可见范围限制以接口返回为准,不尝试绕过。"与"不自动下载媒体、发布内容、提交 Git 或推送。"
- [ok] "已存在默认跳过"的写盘保护属实 — extract_video_transcript.py save_item 依据 overwrite 参数决定是否跳过;SKILL.md 与 agents/openai.yaml 表述一致。
- [ok] 付费与法律提示为强制展示 — SKILL.md"必须先原样展示下面这条提示,不能省略或改写",法律提示文本与脚本 LEGAL_NOTICE 常量同源。
6Verdict & Scenarios
3d8bb7e6cc40716a…