Douyin Video Downloader
Downloads Douyin videos by opening the page in a headless browser, extracting the <video> source URL, and downloading via curl. This bypasses yt-dlp's cookie issues with Douyin's anti-scraping.
Prerequisites
agent-browser(npm i -g agent-browser)curl
Usage
python3 scripts/douyin_download.py <URL> [--output-dir DIR] [--filename NAME]
Supported URL Formats
https://www.douyin.com/video/<id>— direct video pagehttps://www.douyin.com/search/...?modal_id=<id>— search results with video modalhttps://v.douyin.com/<code>— share short linkshttps://www.douyin.com/note/<id>— note/image posts with video
Examples
# Basic download to ~/Downloads
python3 scripts/douyin_download.py 'https://www.douyin.com/video/7577715519366576522'
# Custom output directory and filename
python3 scripts/douyin_download.py 'https://www.douyin.com/video/7577715519366576522' \
-o ~/Videos -f my_video
# From search page URL
python3 scripts/douyin_download.py 'https://www.douyin.com/search/关键词?modal_id=7577715519366576522'
How It Works
- Normalize URL → extract video ID, construct direct video page URL
- Open page in
agent-browser(headless Chromium) - Extract
<video>element'scurrentSrc(CDN direct link) - Close browser
- Download MP4 via
curlwith proper Referer header
Notes
- No login required — fresh browser session is sufficient
- Video title auto-detected from page title for filename
- Large videos may take 30-60s to download depending on network
- CDN links are temporary (~2h validity); download promptly after extraction