CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-youtube-dl

Command-line program to download videos from YouTube.com and other video sites

Overview
Eval results
Files

main-downloader.mddocs/

Main Downloader

The YoutubeDL class is the primary interface for video downloading operations. It orchestrates the entire download process from URL parsing to file output, providing extensive configuration options and hooks for customization.

Capabilities

YoutubeDL Constructor

Creates a new YoutubeDL instance with extensive configuration options for controlling download behavior, output formatting, and processing options.

class YoutubeDL:
    def __init__(self, params=None, auto_init=True):
        """
        Main youtube-dl downloader class.
        
        Parameters:
        - params (dict): Configuration dictionary with download options
        - auto_init (bool): Whether to automatically initialize the instance
        """

Core Download Methods

Primary methods for downloading videos and extracting information from supported sites.

def download(self, url_list):
    """
    Download a list of URLs.
    
    Parameters:
    - url_list (list): List of URLs to download
    
    Returns:
    int: Return code (0 for success, non-zero for errors)
    """

def extract_info(self, url, download=True, ie_key=None, extra_info={}, process=True, force_generic_extractor=False):
    """
    Extract information from URL without necessarily downloading.
    
    Parameters:
    - url (str): URL to extract information from
    - download (bool): Whether to download the video file
    - ie_key (str): Force specific info extractor
    - extra_info (dict): Additional information to merge
    - process (bool): Whether to process the extracted information
    - force_generic_extractor (bool): Force using generic extractor
    
    Returns:
    dict/list: Video information dictionary or list of dictionaries
    """

def process_info(self, info_dict):
    """
    Process extracted information and download if requested.
    
    Parameters:
    - info_dict (dict): Video information dictionary
    
    Returns:
    dict: Processed information dictionary
    """

URL Processing

Methods for handling and validating URLs before processing.

def urlopen(self, req):
    """
    Open URL with configured request parameters.
    
    Parameters:
    - req: Request object or URL string
    
    Returns:
    Response object
    """

def cache_fn(self, path):
    """
    Return cached file path for given path.
    
    Parameters:
    - path (str): File path
    
    Returns:
    str: Cache file path
    """

Progress and Logging

Methods for handling progress reporting and logging during downloads.

def to_screen(self, message, skip_eol=False):
    """
    Print message to screen if not in quiet mode.
    
    Parameters:
    - message (str): Message to display
    - skip_eol (bool): Whether to skip end-of-line
    """

def report_warning(self, message):
    """
    Report a warning message.
    
    Parameters:
    - message (str): Warning message
    """

def report_error(self, message, tb=None):
    """
    Report an error message.
    
    Parameters:
    - message (str): Error message  
    - tb (str): Optional traceback
    """

Playlist and Batch Processing

Methods for handling playlists and multiple URL processing.

def download_with_info_file(self, info_filename):
    """
    Download using information from JSON file.
    
    Parameters:
    - info_filename (str): Path to info JSON file
    
    Returns:
    int: Return code
    """

def prepare_filename(self, info_dict):
    """
    Generate filename from template and video information.
    
    Parameters:
    - info_dict (dict): Video information dictionary
    
    Returns:
    str: Generated filename
    """

Configuration Parameters

The YoutubeDL constructor accepts a comprehensive params dictionary with these key options:

Basic Options

  • username (str): Username for authentication
  • password (str): Password for authentication
  • videopassword (str): Password for video access
  • quiet (bool): Suppress console output
  • verbose (bool): Enable verbose output
  • no_warnings (bool): Suppress warning messages

Download Control

  • format (str): Video format selector (e.g., 'best', 'worst', 'bestaudio')
  • outtmpl (str): Output filename template
  • restrictfilenames (bool): Restrict filenames to ASCII characters
  • ignoreerrors (bool): Continue on download errors
  • nooverwrites (bool): Don't overwrite existing files
  • continuedl (bool): Continue partial downloads
  • retries (int/str): Number of retries or 'infinite'

Network Options

  • socket_timeout (float): Socket timeout in seconds
  • proxy (str): Proxy URL
  • source_address (str): Client-side IP address to bind to
  • sleep_interval (float): Sleep interval between downloads
  • max_sleep_interval (float): Upper bound of sleep interval

Processing Options

  • postprocessors (list): List of post-processor configurations
  • keepvideo (bool): Keep video file after post-processing
  • min_filesize (int): Minimum file size for download
  • max_filesize (int): Maximum file size for download
  • daterange (DateRange): Date range for video filtering

Usage Examples

Basic Download

from youtube_dl import YoutubeDL

ydl_opts = {}
with YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=VIDEO_ID'])

Extract Info Only

with YoutubeDL({'quiet': True}) as ydl:
    info = ydl.extract_info('https://www.youtube.com/watch?v=VIDEO_ID', download=False)
    title = info.get('title', 'Unknown')
    duration = info.get('duration', 0)

Custom Output Template

ydl_opts = {
    'outtmpl': '%(uploader)s/%(title)s.%(ext)s',
    'format': 'best[height<=720]'
}
with YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=VIDEO_ID'])

Install with Tessl CLI

npx tessl i tessl/pypi-youtube-dl

docs

downloaders.md

extractors.md

index.md

main-downloader.md

post-processors.md

utilities.md

tile.json