feat: 新增 douyin-video-download 技能 / Add douyin-video-download skill (#293)

## 可复用场景 / Reusable scenario

抖音视频无水印下载(H5 header 两段式路线):短链解析 → 两段式请求 iesdouyin 分享页取得 ttwid 并提取
videoInfoRes.play_addr → playwm 改 play 去水印 → 下载 → ffprobe
校验。免登录、免浏览器渲染、不读取用户浏览器凭据。适用于 v.douyin.com 短链、iesdouyin 分享链接或纯视频 ID
的下载/保存/去水印需求。

Download Douyin videos without watermark over the H5-header two-pass
route (short-link resolve → ttwid via two-pass share-page fetch →
videoInfoRes play_addr extraction → playwm→play → download → ffprobe
verify). No login, no browser rendering, no user-browser credential
access.

## 来源与许可 / Provenance & license

- 内容为本条目原创(含 scripts/download_douyin.py,纯 Python 标准库),方法于 2026-11-17 在视频
7708667389918858496 上端到端实测通过(1280x720 / 169.18s / 15MB)。
- 许可 MIT;redistribution: allowed;stewardship: community;maintainer:
yi-ge。
- 内容不含凭据、不含临时 ref;合规边界(仅下载有权保存内容)已写入正文。

## 兼容性影响 / Compatibility

- 本地技能(SKILL.md + SKILL.zh-CN.md + scripts/),无需新工具或连接;Python 3 标准库 + 可选
ffprobe 校验。
- 未登记 builtin-skills.json(按需安装即可);manifest.stats.totalSkills 149→150。
- source_hash 已按 translate.py 算法回填,en-US 译文 translated_by: ai(由 AI 译自
zh-CN 源文,已人工复核事实一致性)。

## 已执行校验 / Checks run

- `uv run scripts/i18n/validate-i18n.py skills/douyin-video-download` →
0 error(s)
- `uv run scripts/catalog/validate_catalog_metadata.py
--require-complete` → 0 error(s)(publishableSkills=150)
- `uv run scripts/i18n/translate.py --check
skills/douyin-video-download` → up-to-date (hash match)
- 脚本端到端实测:ffprobe 校验通过,与页面 duration 一致

Co-authored-by: mashagua <993498039@qq.com>
This commit is contained in:
yigeandmashagua authored and GitHub committed 2026-11-19 07:23:21 +08:00
1 parent 99153a097c
commit 7d92094b97
5 files changed
+465 -1

No files matched your search

+165
View File
@@ -0,0 +1,165 @@
---
name: douyin-video-download
description: >-
Download Douyin (抖音) videos without watermark over the H5-header route:
resolve the share short link, obtain the ttwid device cookie via a two-pass
request to the iesdouyin share page, extract the play address from the
embedded videoInfoRes JSON, swap playwm for play to drop the watermark,
download and verify with ffprobe. No login, no browser rendering, no cookie
harvesting from user browsers. Use when the user asks to download, save, or
de-watermark a Douyin video, or when a message contains a v.douyin.com short
link, an iesdouyin share link, or a bare video ID. Trigger words: 下载抖音,
抖音无水印, 保存抖音视频, 解析抖音链接, 抖音视频下载.
license: MIT
version: 1.0.0
type: procedural
risk_level: low
status: enabled
disable-model-invocation: true
tags:
- douyin
- video
- download
- watermark-free
metadata:
author: yi-ge
updated_at: '2026-11-17'
i18n:
default_locale: en-US
source_locale: zh-CN
locales:
- zh-CN
- en-US
zh-CN:
name: 抖音视频下载
short_desc: 抖音视频无水印下载:H5 header 两段式路线,免登录免浏览器
description: 抖音视频无水印下载(H5 header 路线):短链解析、两段式请求 iesdouyin 分享页取得 ttwid 并提取 videoInfoRes 播放地址、playwm 改 play 去水印下载、ffprobe 校验。免登录、免浏览器渲染,不读取用户浏览器凭据。Use when 用户要求下载/保存/解析抖音视频、去水印,或消息含 v.douyin.com 短链、iesdouyin 分享链接、纯视频 ID;触发词:下载抖音、抖音无水印、保存抖音视频、解析抖音链接、抖音视频下载。
body: ./SKILL.zh-CN.md
source_hash: sha256:52f9ef92ca43f7da
translated_by: human
en-US:
name: Douyin Video Download
short_desc: Watermark-free Douyin downloads over the H5-header two-pass route, no login or browser needed
description: >-
Download Douyin videos without watermark over the H5-header route:
resolve the share short link, obtain the ttwid device cookie via a
two-pass request to the iesdouyin share page, extract the play address
from the embedded videoInfoRes JSON, swap playwm for play, download and
verify with ffprobe. No login, no browser rendering, no user-browser
credential access. Use when the user asks to download, save, or
de-watermark a Douyin video, or when a message contains a
v.douyin.com short link, an iesdouyin share link, or a bare video ID.
body: ./SKILL.md
source_hash: sha256:52f9ef92ca43f7da
translated_by: ai
market:
icon: >-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0
24 24" fill="none"><rect x="3" y="5" width="18" height="14" rx="3"
stroke="#007AFF" stroke-width="1.5"/><path d="M10 9.5v5l4.5-2.5L10 9.5z"
fill="#34C759"/><path d="M7 2v3M17 2v3" stroke="#007AFF"
stroke-width="1.5" stroke-linecap="round"/></svg>
short_desc: 抖音视频无水印下载:H5 header 两段式路线,免登录免浏览器
category: productivity
channel: latest
maintainer:
name: yi-ge
verified: false
---
# douyin-video-download Skill
## L0: One-line Summary
Download Douyin videos without watermark via the mobile H5-header route and verify with ffprobe — no login required.
## L1: Overview and Use Cases
### Capability
Run the full chain on a Douyin short link / share link / video ID: resolve the
short link, make a two-pass request to the iesdouyin share page to obtain the
ttwid cookie and extract `videoInfoRes.play_addr`, swap `playwm` for `play` to
drop the watermark, download, and verify with ffprobe. The bundled
`scripts/download_douyin.py` does all of this in one command (stdlib only).
### Use Cases
The user provides a v.douyin.com short link, an iesdouyin share link, or a bare
video ID and asks to download, save, or de-watermark it; or a previous download
attempt failed and needs a reliable path.
### Core Value
No user-browser credentials, no login bridge, no browser rendering — pure
HTTP. Works even for videos whose desktop web API is blocked by msToken/Argus
signing (verified 2026-11).
## L2: Detailed Specification
### Quick start (recommended)
```bash
python3 scripts/download_douyin.py "https://v.douyin.com/<short_id>/" -o out_dir/
python3 scripts/download_douyin.py 7708667389918858496 -o out_dir/
```
The script resolves the short link, obtains ttwid, extracts the play address,
swaps playwm→play, downloads, and runs ffprobe verification. Output:
`<video_id>.mp4` plus metadata. Python standard library only.
### Manual steps (when the script is unavailable)
1. **Resolve the short link**: `curl -sIL -A "$H5UA" "https://v.douyin.com/<short_id>/"`
and take `https://www.iesdouyin.com/share/video/<video_id>/?...&share_sign=...`
from the 302 Location header.
2. **Prepare H5UA**: an iPhone Safari UA, e.g.
`Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1`;
requests must also carry browser-style `Accept`/`Accept-Language` headers.
3. **Two-pass fetch of videoInfoRes**: request
`https://www.iesdouyin.com/share/video/<video_id>/`. The first response only
sets a `ttwid` device-session cookie on the `.iesdouyin.com` domain (not a
login credential); **re-request with that cookie** and the response embeds
`videoInfoRes` at `videoInfoRes.item_list[0].video.play_addr.url_list[0]`,
e.g. `https://aweme.snssdk.com/aweme/v1/playwm/?video_id=<vid>&ratio=720p&line=0`.
Extraction snippet:
```python
block = html[html.find('"videoInfoRes":{'):]
m = re.search(r'"play_addr":\{"uri":"[^"]*","url_list":(\[.*?\])', block)
url = json.loads(m.group(1).replace('\\u002F', '/'))[0]
```
4. **Watermark-free download**: replace `playwm` with `play` in the URL and
download with `curl -sL`, again with the H5 UA + Referer. `url_list` may hold
several addresses — try them in order; the `ratio` tier comes from the share
page.
5. **Verify**: ffprobe for container/duration/resolution; compare with the page
`duration` field (unit may be milliseconds — trust ffprobe).
### Failure memo (verified 2026-11 — do not retry these)
| Path | Symptom |
| --- | --- |
| Desktop web API (/aweme/v1/web/aweme/detail) | Blocked by ArgusSecurityPlugin Uifid Not Found (msToken signing required) |
| yt-dlp 2026.10.26 | Fresh cookies needed (msToken requires JS) |
| Single share-page request (no prior ttwid) | Only Set-Cookie returned; no videoInfoRes |
| Requests without browser-style Accept headers | Slimmed response without videoInfoRes |
| Jina Reader anonymous | IP-reputation rate limit 401 |
| Rendering the Douyin page in a browser | Heavy page — quota kills / navigation timeouts |
### Error handling
- `页面无 videoInfoRes` (no videoInfoRes): confirm the two-pass request ran
(second request carries ttwid) and headers are complete.
- Cannot resolve video_id: the short link may have expired — ask the user to
re-share, or use the bare numeric ID directly.
- Downloaded body < 10KB: likely an error page — try the next `url_list` entry.
- CDN rejects: the download request must also carry the H5 UA + Referer.
### Compliance boundary
Only download content the user is entitled to keep (their own or authorized
material); respect platform terms and copyright; no bulk scraping or
infringing redistribution. Never read user-browser cookies or inject login
credentials.
@@ -0,0 +1,85 @@
<!-- locale: zh-CN -->
# douyin-video-download Skill
## L0:一句话摘要
用移动端 H5 header 请求抖音分享页提取播放地址,免登录下载无水印视频并校验。
## L1:概述与使用场景
### 能力描述
对抖音短链/分享链接/视频 ID 执行完整链路:短链解析 → 两段式请求 iesdouyin 分享页取得
ttwid 并提取 videoInfoRes.play_addr → playwm 改 play 去水印 → 下载 → ffprobe 校验,
产出无水印 MP4。配套脚本 `scripts/download_douyin.py` 一条命令完成。
### 使用场景
用户发来 v.douyin.com 短链、iesdouyin 分享链接或纯视频 ID,要求下载、保存或去水印;
下载失败需要按可靠路径排查。
### 核心价值
不读浏览器凭据、不启动登录桥接、不需要浏览器渲染,纯 HTTP 完成;对桌面 API 被
msToken/Argus 签名拦截的视频同样有效(2026-11 实测)。
## L2:详细规范
### 快速使用(推荐)
```bash
python3 scripts/download_douyin.py "https://v.douyin.com/<short_id>/" -o out_dir/
python3 scripts/download_douyin.py 7708667389918858496 -o out_dir/
```
脚本自动完成:短链解析、ttwid 获取、播放地址提取、playwm→play、下载、ffprobe 校验。
输出 `<video_id>.mp4` 与元数据。脚本仅依赖 Python 标准库。
### 手动步骤(脚本不可用时)
1. **短链解析**:`curl -sIL -A "$H5UA" "https://v.douyin.com/<short_id>/"`,从 302
Location 取 `https://www.iesdouyin.com/share/video/<video_id>/?...&share_sign=...`。
2. **准备 H5UA**:iPhone Safari UA,例如
`Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1`;
请求需附带浏览器式 `Accept`/`Accept-Language` 头。
3. **两段式取得 videoInfoRes**:请求 `https://www.iesdouyin.com/share/video/<video_id>/`。
首次响应只在 `.iesdouyin.com` 域下发 `ttwid`(设备会话标识,非登录凭据);**带上该
cookie 再次请求**,响应才内嵌 `videoInfoRes`。路径:
`videoInfoRes.item_list[0].video.play_addr.url_list[0]`,形如
`https://aweme.snssdk.com/aweme/v1/playwm/?video_id=<vid>&ratio=720p&line=0`。
提取片段:
```python
block = html[html.find('"videoInfoRes":{'):]
m = re.search(r'"play_addr":\{"uri":"[^"]*","url_list":(\[.*?\])', block)
url = json.loads(m.group(1).replace('\\u002F', '/'))[0]
```
4. **去水印下载**:URL 中 `playwm` 替换为 `play`,`curl -sL` 同样带 H5 UA + Referer
下载。`url_list` 可能有多个地址,逐个尝试;`ratio` 档位由分享页给出。
5. **校验**:ffprobe 查容器/时长/分辨率,与页面 `duration` 字段比对(单位可能是毫秒,
以 ffprobe 为准)。
### 失败路径备忘(2026-11 实测,勿再走弯路)
| 路径 | 现象 |
| --- | --- |
| 桌面 web API(/aweme/v1/web/aweme/detail) | Blocked by ArgusSecurityPlugin Uifid Not Found(需 msToken 签名) |
| yt-dlp 2026.10.26 | Fresh cookies needed(msToken 需 JS 生成) |
| 分享页单次请求(无既有 ttwid) | 只拿到 Set-Cookie,响应无 videoInfoRes |
| 不带浏览器式 Accept 头 | 响应精简,无 videoInfoRes |
| Jina Reader 匿名 | IP 信誉限流 401 |
| 浏览器渲染抖音页 | 页面资源重,易触发配额终止/导航超时 |
### 错误处理
- `页面无 videoInfoRes`:确认两段式已执行(第二次请求带 ttwid)且请求头完整。
- `无法解析 video_id`:短链可能过期,让用户重新分享;或直接用纯数字 ID。
- 下载返回体过小(<10KB):多半是错误页,换 `url_list` 下一个地址。
- CDN 拒绝:下载请求必须同样带 H5 UA + Referer。
### 合规边界
仅下载用户有权保存的内容(自有/获授权素材);遵守平台服务条款与版权,不用于批量
抓取或传播侵权内容。不读取浏览器 Cookie、不注入登录凭据。
@@ -0,0 +1,75 @@
{
"$schema": "../../schemas/catalog-metadata.v1.schema.json",
"schemaVersion": 1,
"identity": {
"kind": "skill",
"id": "douyin-video-download"
},
"presentation": {
"defaultLocale": "en-US",
"i18n": {
"zh-CN": {
"name": "抖音视频下载",
"summary": "抖音视频无水印下载:H5 header 两段式路线,免登录免浏览器",
"description": "抖音视频无水印下载(H5 header 路线):短链解析、两段式请求 iesdouyin 分享页取得 ttwid 并提取 videoInfoRes 播放地址、playwm 改 play 去水印下载、ffprobe 校验。免登录、免浏览器渲染,不读取用户浏览器凭据。Use when 用户要求下载/保存/解析抖音视频、去水印,或消息含 v.douyin.com 短链、iesdouyin 分享链接、纯视频 ID;触发词:下载抖音、抖音无水印、保存抖音视频、解析抖音链接、抖音视频下载。"
},
"en-US": {
"name": "Douyin Video Download",
"summary": "Watermark-free Douyin downloads over the H5-header two-pass route, no login or browser needed",
"description": "Download Douyin videos without watermark over the H5-header route: resolve the share short link, obtain the ttwid device cookie via a two-pass request to the iesdouyin share page, extract the play address from the embedded videoInfoRes JSON, swap playwm for play, download and verify with ffprobe. No login, no browser rendering, no user-browser credential access. Use when the user asks to download, save, or de-watermark a Douyin video, or when a message contains a v.douyin.com short link, an iesdouyin share link, or a bare video ID."
}
},
"category": "productivity",
"tags": [
"douyin",
"video",
"download",
"watermark-free"
]
},
"release": {
"state": "known",
"version": "1.0.0",
"versionScheme": "semver"
},
"timestamps": {
"catalogUpdatedAt": {
"state": "known",
"value": "2026-11-17",
"precision": "day"
},
"releasePublishedAt": {
"state": "unknown"
},
"reviewedAt": {
"state": "unknown"
},
"upstreamObservedAt": {
"state": "unknown"
}
},
"provenance": {},
"governance": {
"stewardship": "community",
"availability": "installable",
"license": {
"state": "known",
"value": "MIT"
},
"redistribution": "allowed",
"listingMaintainer": {
"name": "yi-ge",
"verified": false
}
},
"compatibility": {
"platforms": {
"state": "unknown"
}
},
"spec": {
"kind": "skill",
"riskLevel": "low",
"skillType": "procedural"
}
}
@@ -0,0 +1,139 @@
#!/usr/bin/env python3
"""抖音视频无水印下载(H5 header 路线)。
用法:
python3 download_douyin.py "https://v.douyin.com/<short_id>/" -o out_dir/
python3 download_douyin.py 7708667389918858496 -o out_dir/
原理: 短链解析 -> ttwid cookie -> iPhone UA + Referer 请求 iesdouyin 分享页
-> videoInfoRes.item_list[0].video.play_addr.url_list -> playwm 改 play -> 下载 -> 校验。
"""
import argparse
import http.cookiejar
import json
import os
import re
import shutil
import subprocess
import sys
import urllib.request
H5UA = (
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) "
"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 "
"Mobile/15E148 Safari/604.1"
)
REFERER = "https://www.iesdouyin.com/"
def _opener(cj: http.cookiejar.CookieJar):
return urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
HEADERS = {
"User-Agent": H5UA,
"Referer": REFERER,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.9",
}
def fetch(url: str, cj: http.cookiejar.CookieJar, timeout: int = 60) -> bytes:
req = urllib.request.Request(url, headers=HEADERS)
with _opener(cj).open(req, timeout=timeout) as resp:
return resp.read()
def resolve_video_id(source: str, cj: http.cookiejar.CookieJar) -> str:
if re.fullmatch(r"\d{15,25}", source):
return source
req = urllib.request.Request(source, headers={"User-Agent": H5UA})
with _opener(cj).open(req, timeout=30) as resp:
final = resp.geturl()
m = re.search(r"/(?:share/)?video/(\d+)", final)
if not m:
raise SystemExit(f"无法从跳转地址解析 video_id: {final}")
return m.group(1)
def extract_play_urls(html: str):
"""返回 (播放地址列表[已去水印], 页面duration数值或None)。"""
i = html.find('"videoInfoRes":{')
if i < 0:
raise SystemExit(
"页面无 videoInfoRes:请确认同时提供了 iPhone H5 UA、"
"Referer: https://www.iesdouyin.com/ 与 ttwid cookie(三要素缺一不可)"
)
block = html[i:]
m = re.search(r'"play_addr":\{"uri":"[^"]*","url_list":(\[.*?\])', block)
if not m:
raise SystemExit("videoInfoRes 中未找到 play_addr.url_list")
urls = json.loads(m.group(1).replace("\\u002F", "/"))
dur = re.search(r'"duration":(\d+)', block)
urls = [u.replace("playwm", "play") for u in urls]
return urls, (int(dur.group(1)) if dur else None)
def verify(path: str) -> None:
ffprobe = shutil.which("ffprobe") or os.environ.get("FFPROBE") or (
"/Users/yige/.desirecore/runtime/toolkits/ffmpeg/7.1.5-dc1/bin/ffprobe"
if os.name == "darwin" else ""
)
if not ffprobe or not os.path.exists(ffprobe):
print("ffprobe 不可用,跳过元数据校验(文件已下载)")
return
out = subprocess.run(
[ffprobe, "-v", "error", "-show_entries",
"format=duration,size:stream=codec_type,codec_name,width,height",
"-of", "default=noprint_wrappers=1", path],
capture_output=True, text=True,
)
print("=== ffprobe ===")
print(out.stdout.strip())
def main() -> None:
ap = argparse.ArgumentParser(description="抖音视频无水印下载(H5 header 路线)")
ap.add_argument("source", help="抖音短链 / 分享链接 / 纯 video_id")
ap.add_argument("-o", "--out", default=".", help="输出目录(默认当前目录)")
ap.add_argument("-n", "--name", default=None, help="输出文件名(默认 <video_id>.mp4)")
args = ap.parse_args()
cj = http.cookiejar.CookieJar()
try: # ttwid 是设备会话 cookie,不是登录凭据
fetch("https://www.douyin.com/", cj)
except Exception:
pass
vid = resolve_video_id(args.source, cj)
print(f"video_id: {vid}")
share_url = f"https://www.iesdouyin.com/share/video/{vid}/"
html = fetch(share_url, cj).decode("utf-8", "replace")
if '"videoInfoRes"' not in html:
# iesdouyin 首次响应只下发 ttwid;带 cookie 二次请求才返回 videoInfoRes
html = fetch(share_url, cj).decode("utf-8", "replace")
urls, duration = extract_play_urls(html)
if duration:
print(f"页面 duration: {duration}(注意单位,可能是毫秒)")
os.makedirs(args.out, exist_ok=True)
out_path = os.path.join(args.out, args.name or f"{vid}.mp4")
for u in urls:
print(f"尝试播放地址: {u[:100]}...")
try:
data = fetch(u, cj)
if len(data) < 10_000:
print(" 返回过小,判定无效,换下一个", file=sys.stderr)
continue
with open(out_path, "wb") as f:
f.write(data)
print(f"下载完成: {out_path} ({len(data)} bytes)")
verify(out_path)
return
except Exception as exc: # noqa: BLE001
print(f" 失败: {exc}", file=sys.stderr)
raise SystemExit("所有播放地址均下载失败")
if __name__ == "__main__":
main()