使用 yt-dlp 从 YouTube、Bilibili、Twitter 等数千个网站下载视频。当用户提供视频链接并想下载时使用,...
Download videos from thousands of websites using yt-dlp.
Before downloading, verify dependencies are installed:
bash
# Check yt-dlp
which yt-dlp || echo "yt-dlp not installed. Install with: pip install yt-dlp"
# Check ffmpeg (required for audio extraction and format merging)
which ffmpeg || echo "ffmpeg not installed. Install with: brew install ffmpeg"
If not installed, install them first:
bash
pip install yt-dlp
brew install ffmpeg # macOS
bash
yt-dlp -P "~/Downloads/yt-dlp" "VIDEO_URL"
YouTube often blocks direct downloads with 403 errors. Always use browser cookies for YouTube:
bash
yt-dlp -P "~/Downloads/yt-dlp" --cookies-from-browser chrome "YOUTUBE_URL"
Supported browsers: chrome, firefox, safari, edge, brave, opera
bash
yt-dlp -P "/path/to/save" -o "%(title)s.%(ext)s" "VIDEO_URL"
bash
yt-dlp -P "~/Downloads/yt-dlp" "VIDEO_URL"
bash
yt-dlp -P "~/Downloads/yt-dlp" -x --audio-format mp3 "VIDEO_URL"
bash
yt-dlp -P "~/Downloads/yt-dlp" --write-subs --sub-langs all "VIDEO_URL"
720p:
bash
yt-dlp -P "~/Downloads/yt-dlp" -f "bestvideo[height<=720]+bestaudio/best[height<=720]" "VIDEO_URL"
1080p:
bash
yt-dlp -P "~/Downloads/yt-dlp" -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" "VIDEO_URL"
Best available:
bash
yt-dlp -P "~/Downloads/yt-dlp" -f "bestvideo+bestaudio/best" "VIDEO_URL"
bash
yt-dlp -F "VIDEO_URL"
Then download specific format by ID:
bash
yt-dlp -P "~/Downloads/yt-dlp" -f FORMAT_ID "VIDEO_URL"
bash
# Download entire playlist
yt-dlp -P "~/Downloads/yt-dlp" -o "%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" "PLAYLIST_URL"
# Download specific range (e.g., items 1-5)
yt-dlp -P "~/Downloads/yt-dlp" -I 1:5 "PLAYLIST_URL"
bash
yt-dlp -P "~/Downloads/yt-dlp" --write-thumbnail "VIDEO_URL"
When user provides a video URL:
Identify the platform:
--cookies-from-browser chromeAsk what they want (if not specified):
Construct the command based on requirements
http:// or https:// URLsevalExecute the download using Shell tool with required_permissions: ["all", "network"]
Handle errors:
--cookies-from-browser-F to list formats, then selectReport the result - file location and any errors
User: "帮我下载这个视频 https://www.youtube.com/watch?v=xxx"
Response:
bash
# YouTube - use cookies to avoid 403 errors
yt-dlp -P "~/Downloads/yt-dlp" --cookies-from-browser chrome "https://www.youtube.com/watch?v=xxx"
User: "下载这个视频的音频 https://www.bilibili.com/video/xxx"
Response:
bash
# Bilibili - extracting audio as MP3
yt-dlp -P "~/Downloads/yt-dlp" -x --audio-format mp3 "https://www.bilibili.com/video/xxx"
User: "下载这个 Twitter 视频 https://twitter.com/xxx/status/123"
Response:
bash
# Twitter/X - direct download usually works
yt-dlp -P "~/Downloads/yt-dlp" "https://twitter.com/xxx/status/123"
yt-dlp supports thousands of sites including:
Full list: https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md
ErrorCauseSolutionHTTP 403 ForbiddenYouTube blocks unauthenticated requestsUse --cookies-from-browser chromeVideo unavailableGeo-restricted or privateUse cookies or VPNDownload interruptedNetwork issuesRetry - yt-dlp auto-resumesFormat not availableRequested format doesn't existUse -F to list formats
bash
pip install yt-dlp
bash
brew install ffmpeg # macOS
This is the most common YouTube error. Always use cookies for YouTube:
bash
# Recommended approach for YouTube
yt-dlp -P "~/Downloads/yt-dlp" --cookies-from-browser chrome "YOUTUBE_URL"
Supported browsers: chrome, firefox, safari, edge, brave, opera
bash
# Try with cookies from browser
yt-dlp --cookies-from-browser chrome "VIDEO_URL"
# Or use a specific format
yt-dlp -F "VIDEO_URL" # List formats first
yt-dlp -f FORMAT_ID "VIDEO_URL"
bash
# Update yt-dlp to latest version
pip install -U yt-dlp
# Force IPv4 (sometimes helps with connection issues)
yt-dlp -4 "VIDEO_URL"
--cookies-from-browser chromepip install -U yt-dlp-F before downloading if unsure