- Route all node and yt-dlp output through a logger that survives a closed/detached stdout (ComfyUI launched from a terminal that has since closed raised BrokenPipeError on every print, aborting downloads and masking real errors). - Remove the hardcoded browser User-Agent: yt-dlp sends a UA matching the player client it impersonates, and the stale Chrome UA made YouTube refuse the player response entirely. - Remove default extractor_args (player_skip + pinned legacy clients): they hid all adaptive formats, capping "highest" at 360p. The HTTP 403 handler still applies alternative player clients as a fallback. - Fix the quality filter: "360p" is now stripped to a number and the height cap applies to every format alternative (previously it only modified the last fallback, so selecting 360p could download 4K). - Detect YouTube's SABR-only streaming experiment (yt-dlp#12482), which leaves some sessions with only progressive 360p formats, and retry with a fresh session. - Apply the same fixes to the /yt_dl/api/ytdl endpoint. - Add cookies helper, test script, and .gitignore. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ComfyUI-yt_dl
Download YouTube videos using ComfyUI with enhanced error handling and anti-blocking measures.
Features
- Download YouTube videos, audio, and subtitles
- Support for multiple quality options (highest, 144p, 360p, 720p)
- Enhanced anti-blocking measures to handle HTTP 403 errors
- Automatic retry mechanism with fallback strategies
- Optional cookies support for authenticated requests
- Support for Twitter/X videos
- Automatically download
.srtsubtitles alongside video downloads (original language + English by default) - Web API endpoint for external integration
Installation
-
Clone this repository into your
ComfyUI/custom_nodes/directory:cd ComfyUI/custom_nodes/ git clone https://github.com/yourusername/ComfyUI-yt_dl.git -
Install the required dependencies:
pip install -r requirements.txt -
Restart ComfyUI
Usage
In ComfyUI Interface
- Look for "YouTube Download" node in the node browser
- Add the node to your workflow
- Configure:
- URL: The YouTube video URL
- Mode: video, audio, or subtitles
- Quality: highest, 144p, 360p, or 720p (video mode only)
- Subtitle Languages (optional): comma-separated list (e.g.
original,en). Leave blank to use the defaultoriginal,en.
- Connect the output to other nodes or use the PreviewAny node
Using the Menu Button
The extension adds a "YouTube DL" button to ComfyUI's top menu. Click it to:
- Enter a YouTube URL
- Select mode (video/audio/subtitles)
- Select quality (for video mode)
- Optionally set subtitle languages if you want something other than the defaults
- Automatically create a download node with your settings
Subtitle Languages
The downloader requests subtitles when grabbing a video. By default it downloads the original language alongside English (original,en). You can customize this by setting the Subtitle Languages input to a comma-separated list (for example pt,en, ja, or all).
⚠️ Requesting all languages can trigger YouTube rate-limiting and may slow down downloads. Prefer a small list of languages you actually need.
Troubleshooting HTTP 403 Errors
YouTube sometimes blocks download requests. This extension includes several measures to handle this:
Automatic Fixes (Applied Automatically)
- Retry mechanisms with fallback strategies
- Fallback to alternative player clients (android, web) on HTTP 403
- Automatic retry when YouTube's SABR-only experiment limits a session to 360p
- Rate limiting to avoid detection
- Safe logging that survives a detached/closed stdout (no more BrokenPipeError)
Manual Solutions
Option 1: Use Browser Cookies
If automatic fixes don't work, try using browser cookies:
# Run the cookies extractor script
python get_cookies.py
This will attempt to extract cookies from your browser. If successful, it will save them to output/yt_dl/cookies.txt and the downloader will use them automatically.
Option 2: Manual Cookie Export
- Install a browser extension:
- Chrome: "Get cookies.txt LOCALLY"
- Firefox: "Export Cookies"
- Export cookies from youtube.com
- Save the file as
output/yt_dl/cookies.txtin your ComfyUI directory
Option 3: Update yt-dlp
Make sure you have the latest version:
pip install --upgrade yt-dlp
API Endpoint
The extension provides a web API endpoint:
POST /yt_dl/api/ytdl
Request Body:
{
"url": "https://www.youtube.com/watch?v=VIDEO_ID",
"mode": "video",
"quality": "highest"
}
Response:
{
"file_path": "/path/to/downloaded/file.mp4"
}
Supported Sites
- YouTube (primary support)
- Twitter/X (basic support)
- Generic sites (fallback)
Error Handling
The extension includes comprehensive error handling:
- Automatic retry on HTTP 403 errors
- Fallback strategies for different player clients
- Detailed error messages in ComfyUI console
- Graceful degradation when features aren't available
Requirements
- yt-dlp >= 2024.8.6
- ComfyUI
License
MIT License