How you-get Handles Stream Selection with Multiple Quality Options

you-get automatically selects the highest-quality stream by sorting available formats according to a predefined priority list in stream_types, defaulting to the first entry while allowing users to override with --itag or --format flags.

When downloading videos from platforms like YouTube or Bilibili, you-get must resolve multiple available quality levels into a single download target. Understanding how this open-source tool prioritizes streams helps you control downloads effectively without manually inspecting every option.

How you-get Organizes Available Stream Formats

The you-get architecture separates stream metadata into distinct containers based on delivery method. Each extractor populates these containers during the parsing phase.

The streams and dash_streams Dictionaries

you-get maintains two primary dictionaries to hold available media:

  • self.streams – Stores non-DASH (single-file) streams. For YouTube, these populate from the formats array in the player response, keyed by itag values.
  • self.dash_streams – Stores DASH (adaptive) streams with separate video and audio tracks. These populate from the adaptiveFormats array, also keyed by itag.

The stream_types Priority List

Every extractor defines a class attribute called stream_types that lists supported formats in descending quality order. In src/you_get/extractors/youtube.py (lines 18-76), this list begins with itag 38 (3072p) and descends through itag 17 (144p). This ordered list serves as the master priority reference for quality selection.

The Stream Selection Algorithm in you-get

Once the extractor populates the stream dictionaries, the base VideoExtractor class applies a deterministic sorting and selection process.

Building the Sorted Stream List

During download_by_url or download_by_vid, the extractor creates self.streams_sorted by filtering stream_types against actually available streams. The code in src/you_get/extractor.py (lines 54-57) implements this as a list comprehension:

self.streams_sorted = [
    dict([('id', stream_type['id'])] + list(self.streams[stream_type['id']].items()))
    for stream_type in self.__class__.stream_types
    if stream_type['id'] in self.streams
]

This construction preserves the quality order defined in stream_types, ensuring the first element represents the best available quality.

Default Selection Behavior

When you invoke you-get URL without quality flags, the download routine selects the first element of self.streams_sorted. The logic in src/you_get/extractor.py (lines 100-112) retrieves the stream identifier:

stream_id = self.streams_sorted[0]['id'] if 'id' in self.streams_sorted[0] else self.streams_sorted[0]['itag']

This guarantees the highest-quality available stream becomes the default download target.

DASH Stream Prioritization

When DASH streams are present and ffmpeg is installed, you-get applies a different quality heuristic. Instead of using the stream_types order, it sorts DASH streams by total file size, assuming larger size correlates with higher resolution. The code in src/you_get/extractor.py (lines 102-110) implements this:

itags = sorted(self.dash_streams,
               key=lambda i: -self.dash_streams[i]['size'])
stream_id = itags[0]  # highest-size DASH stream

This ensures DASH variants are selected based on actual data volume rather than metadata tags alone.

Overriding Automatic Stream Selection

you-get provides explicit flags to bypass the default quality selection algorithm.

Selecting Streams by itag

Use the --itag (or -i) flag followed by the specific itag identifier to force download of a particular quality level. For example, to download the 720p version (itag 22) of a YouTube video:

you-get -i 22 "https://www.youtube.com/watch?v=abc123"

The extractor validates the supplied itag against self.streams and self.dash_streams in src/you_get/extractor.py (lines 122-128). If the identifier is missing, you-get aborts with an error message.

Using the format Flag

For extractors that use generic format identifiers rather than YouTube-specific itags, use the --format flag followed by the format ID. This operates identically to --itag but matches against the id field in stream_types definitions for non-YouTube sites.

Practical Code Examples

The following commands demonstrate stream selection behavior in practice:


# Download the highest-quality stream (default behavior)

you-get "https://www.youtube.com/watch?v=abc123"

# List all available streams without downloading

you-get -i "" "https://www.youtube.com/watch?v=abc123"

# Download a specific quality using itag (e.g., 720p)

you-get -i 22 "https://www.youtube.com/watch?v=abc123"

# Download using format identifier for non-YouTube sites

you-get --format hd "https://example.com/video"

In the first command, you-get builds self.streams_sorted from the extractor's stream_types, selects the first entry, and downloads the corresponding URL. The second command triggers info_only mode to display the full sorted list without fetching data.

Summary

  • stream_types defines the quality priority order for each extractor in descending quality sequence.
  • self.streams_sorted is constructed by filtering available streams against the priority list, ensuring the best quality appears first.
  • Default selection automatically picks the first element of self.streams_sorted when no quality flags are provided.
  • DASH handling prefers the stream with the largest total file size when adaptive formats are available and ffmpeg is present.
  • Manual override via --itag or --format allows explicit selection of specific quality identifiers, validated against available streams.

Frequently Asked Questions

How does you-get choose between DASH and non-DASH streams?

When ffmpeg is installed on the system, you-get prioritizes DASH streams by sorting them according to total file size and selecting the largest. This occurs in src/you_get/extractor.py where the code checks for DASH availability before falling back to the standard streams_sorted list. Without ffmpeg, the tool defaults to non-DASH streams to avoid merge complications.

What happens if the requested itag is not available?

If you specify an itag via --itag that does not exist in either self.streams or self.dash_streams, you-get validates the input against available dictionaries in src/you_get/extractor.py (lines 122-128) and terminates with an error message indicating the format is unavailable. The tool does not attempt to download or fall back to alternative qualities when an explicit itag is requested but missing.

Can I list all available streams without downloading?

Yes. Invoke you-get with the -i flag followed by an empty string to trigger info_only mode: you-get -i "" "URL". This forces the extractor to build and display self.streams_sorted and self.dash_streams without initiating the download routine, allowing you to inspect itags, resolutions, and file sizes before selecting a specific quality.

Where is the stream quality priority defined for each site?

Each extractor module defines a class attribute named stream_types that lists supported formats in descending quality order. For example, src/you_get/extractors/youtube.py (lines 18-76) defines the YouTube priority table starting with itag 38 (3072p) and ending with itag 17 (144p). Site-specific extractors like bilibili.py maintain similar ordered lists that the base VideoExtractor class uses to construct self.streams_sorted.

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 →