ytdl-org/youtube-dl · warning · ExtractorError

requested format not available

Error message

requested format not available

What it means

DateRange.__init__ raises this ValueError when the parsed start date is strictly after the parsed end date. DateRange backs youtube-dl's --date-after/--date-before (and --date) filtering; the check is a plain sanity assertion that the interval is non-empty. Dates are parsed with date_from_str, which also supports relative expressions like 'now-1week' and 'today'.

Source

Thrown at youtube_dl/YoutubeDL.py:1858

        # as well.
        # We will pass a context object containing all necessary additional data
        # instead of just formats.
        # This fixes incorrect format selection issue (see
        # https://github.com/ytdl-org/youtube-dl/issues/10083).
        incomplete_formats = (
            # All formats are video-only or
            all(f.get('vcodec') != 'none' and f.get('acodec') == 'none' for f in formats)
            # all formats are audio-only
            or all(f.get('vcodec') == 'none' and f.get('acodec') != 'none' for f in formats))

        ctx = {
            'formats': formats,
            'incomplete_formats': incomplete_formats,
        }

        formats_to_download = list(format_selector(ctx))
        if not formats_to_download:
            raise ExtractorError('requested format not available',
                                 expected=True)

        if download:
            if len(formats_to_download) > 1:
                self.to_screen('[info] %s: downloading video in %s formats' % (info_dict['id'], len(formats_to_download)))
            for format in formats_to_download:
                new_info = dict(info_dict)
                new_info.update(format)
                self.process_info(new_info)
        # We update the info dict with the best quality format (backwards compatibility)
        info_dict.update(formats_to_download[-1])
        return info_dict

    def process_subtitles(self, video_id, normal_subtitles, automatic_captions):
        """Select the requested subtitles and their format"""
        available_subs = {}
        if normal_subtitles and self.params.get('writesubtitles'):
            available_subs.update(normal_subtitles)

View on GitHub (pinned to 956b8c5855)

Solutions

  1. Swap or fix the bounds so start <= end (DateRange('20191201', '20191231')).
  2. If bounds come from variables, normalize them first: start, end = min(start, end), max(start, end).
  3. Double-check relative syntax: --date-after now-1week --date-before now is valid; the reverse order is not.
  4. Verify date strings match the accepted format (YYYYMMDD or supported relative forms) — malformed values often parse to unexpected dates and then invert the range.

Example fix

# before
range_ = DateRange(args.after, args.before)  # raises if after > before

# after
start, end = sorted([args.after, args.before])
range_ = DateRange(start, end)
Defensive patterns

Strategy: validation

Validate before calling

from youtube_dl.utils import DateRange, date_from_str

def safe_range(start, end):
    s = date_from_str(start) if start else None
    e = date_from_str(end) if end else None
    if s and e and s > e:
        raise ValueError('start %s is after end %s' % (s, e))
    return DateRange(start, end)

Try / catch

from youtube_dl.utils import DateRange
try:
    dr = DateRange(after, before)
except ValueError as e:
    if 'start date must be before the end date' in str(e):
        after, before = sorted([after, before])
        dr = DateRange(after, before)
    else:
        raise

Prevention

When it happens

Trigger: Passing DateRange('20191231', '20191201'), or on the CLI --date-after 20191231 --date-before 20191201. Relative expressions can also produce inverted ranges, e.g. --date-after today --date-before yesterday, or a negative window like DateRange('now-1days','now-2days').

Common situations: Script-generated date windows where the bounds are computed independently and end up swapped; misunderstanding that --date-before is the exclusive/inclusive upper bound vs --date-after; typos in YYYYMMDD strings ordering them backwards; timezone shifts making 'today' vs 'now' comparisons invert near midnight UTC.

Related errors


AI-assisted analysis of ytdl-org/youtube-dl@956b8c5855 (2026-08-14). Data as JSON: /api/errors/1bc314c8f4c29875. Report an issue: GitHub.