How Playlist Download Mode Iterates and Processes Multiple Videos in You-Get

You-get's playlist download mode parses the playlist page to extract individual video IDs, then recursively invokes the single-video downloader for each entry while preserving order through enumeration.

The open-source video downloader you-get supports batch processing through its playlist download mode, triggered by the -l or --playlist flag. Unlike single-video extraction, this mode treats the input URL as a container of multiple media files, requiring a specialized iteration mechanism. Understanding how you-get processes playlists requires examining the interaction between the CLI dispatcher, base extractor logic in src/you_get/extractor.py, and site-specific implementations like src/you_get/extractors/youtube.py.

How the Playlist Download Mode Works

When you invoke you-get with the playlist flag, the program enters a specialized code path that separates playlist parsing from individual video downloading. The architecture follows a delegation pattern: the CLI identifies the flag, the base extractor routes to playlist-specific methods, and concrete extractors handle site-specific parsing and iteration.

Step-by-Step Execution Flow

CLI Argument Parsing and Flag Detection

In src/you_get/__main__.py, the argument parser defines the -l/--playlist option. When present, this flag propagates through the opt variable and passes into the download dispatcher as playlist=True within the keyword arguments.

Extractor Dispatch and Method Routing

The download_by_url method in src/you_get/extractor.py serves as the central router. It inspects kwargs.get('playlist') and, when true, delegates execution to download_playlist_by_url instead of the standard single-video routine.

Playlist Data Extraction and Parsing

Concrete extractors implement download_playlist_by_url to handle site-specific playlist structures. For example, in src/you_get/extractors/youtube.py, the method constructs the playlist URL, fetches the page content, and extracts the JSON data containing all video entries. The playlist title is stored in self.title, and self.p_playlist() outputs a formatted header showing the site name, playlist title, and video list.

Iteration and Individual Video Processing

The core iteration logic resides in the enumeration loop:

for index, video in enumerate(videos, 1):
    vid = video['playlistVideoRenderer']['videoId']

For each entry, the extractor creates a new instance of itself (self.__class__()) and calls download_by_url recursively with the single-video URL constructed via get_url_from_vid(vid). The current index passes forward to ensure output files receive sequential numbering prefixes.

Single-Video Download Completion

The recursive call enters the standard single-video extraction path in extractor.py, eventually reaching VideoExtractor.download. This method handles stream selection, file writing, and actual data download, treating the playlist item as an independent video file.

Key Source Files and Functions

Understanding the playlist download mode requires familiarity with these components:

  • src/you_get/__main__.py: Parses the -l/--playlist CLI flag and initiates the download workflow.
  • src/you_get/common.py: Contains helper functions like download_by_url and download_playlist that forward the playlist parameter to extractors.
  • src/you_get/extractor.py: Defines VideoExtractor.download_by_url, which routes to download_playlist_by_url when the playlist flag is active.
  • src/you_get/extractors/youtube.py: Representative implementation showing playlist JSON parsing, enumeration logic, and recursive single-video downloading.
  • Platform-specific extractors (e.g., tudou.py, ximalaya.py): Provide analogous download_playlist_by_url methods for their respective sites.
  • src/you_get/util/*: Utility modules (fs.py, log.py, etc.) used throughout the download flow.

Practical Usage Examples

Invoke playlist mode from the command line:


# Download entire YouTube playlist with sequential numbering

you-get -l "https://www.youtube.com/playlist?list=PL12345ABCDE"

# Download to specific directory

you-get -l -o ./my_playlist "https://www.youtube.com/playlist?list=PL12345ABCDE"

Programmatic usage through the Python API:

from you_get.common import download_playlist

download_playlist(
    url="https://www.youtube.com/playlist?list=PL12345ABCDE",
    output_dir="my_playlist",
    merge=False,          # Keep separate files

    info_only=False       # Perform actual download

)

Both approaches trigger the same internal path: parsing the playlist structure, enumerating entries, and recursively processing each video individually.

Summary

  • Playlist download mode activates when you pass the -l or --playlist flag to you-get.
  • The CLI in __main__.py detects the flag and propagates it through the download dispatcher.
  • Base extractor logic in extractor.py routes playlist requests to download_playlist_by_url instead of single-video methods.
  • Site-specific extractors parse playlist pages, extract video IDs, and store metadata like titles.
  • Enumeration logic iterates through each video entry, creating new extractor instances and recursively calling single-video download methods.
  • Sequential numbering is preserved by passing the enumeration index through recursive calls, ensuring output files maintain playlist order.

Frequently Asked Questions

What is the difference between single-video and playlist download mode in you-get?

Single-video mode extracts and downloads one media file from a direct URL. Playlist download mode treats the URL as a container, parses the playlist structure to extract multiple video IDs, and iterates through each entry to download them sequentially. The playlist flag triggers the download_playlist_by_url method instead of the standard download routine.

How does you-get maintain the correct order when downloading playlist videos?

You-get preserves playlist order through Python's enumerate function, starting the index at 1. During iteration in download_playlist_by_url, the current index passes as a parameter to recursive download_by_url calls. This index prefixes the output filename, ensuring the downloaded files reflect the original playlist sequence regardless of download completion order.

Can I download playlists from sites other than YouTube using you-get?

Yes, you-get supports playlist download mode for multiple platforms including Tudou, Ximalaya, and others. Each site-specific extractor in src/you_get/extractors/ implements its own download_playlist_by_url method to handle platform-specific playlist structures. The base extractor architecture ensures consistent behavior across all supported sites once the playlist flag is activated.

Why does you-get create new extractor instances for each playlist video instead of reusing the same instance?

You-get instantiates a fresh extractor class (self.__class__()) for each video to ensure clean state isolation. This prevents metadata pollution between playlist entries, such as title conflicts or stream URL carryover from previous videos. By recursively calling download_by_url on a new instance, each video processes independently while maintaining the sequential index parameter for proper file naming.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →