impactframesandClaude Opus 5 21090baf28 Fix broken-pipe crashes, 360p quality cap, and failed extractions
- 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>
2026-08-14 16:58:40 +01:00
2025-08-13 15:47:44 +01:00

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 .srt subtitles alongside video downloads (original language + English by default)
  • Web API endpoint for external integration

Installation

  1. Clone this repository into your ComfyUI/custom_nodes/ directory:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/yourusername/ComfyUI-yt_dl.git
    
  2. Install the required dependencies:

    pip install -r requirements.txt
    
  3. Restart ComfyUI

Usage

In ComfyUI Interface

  1. Look for "YouTube Download" node in the node browser
  2. Add the node to your workflow
  3. 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 default original,en.
  4. 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:

  1. Enter a YouTube URL
  2. Select mode (video/audio/subtitles)
  3. Select quality (for video mode)
  4. Optionally set subtitle languages if you want something other than the defaults
  5. 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.

  1. Install a browser extension:
    • Chrome: "Get cookies.txt LOCALLY"
    • Firefox: "Export Cookies"
  2. Export cookies from youtube.com
  3. Save the file as output/yt_dl/cookies.txt in 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

S
Description
No description provided
Readme
41 KiB
Languages
Python 83.1%
JavaScript 16.9%