ytdl-org/youtube-dl · error · ExtractorError

not a media file

Error message

not a media file

What it means

RaiIE (the older link-resolver path, around line 502) inspects media['type'] from the resolved media JSON: if it contains 'Audio' it builds an audio format, if it contains 'Video' it uses _extract_relinker_info, otherwise it raises ExtractorError('not a media file'). The check is substring-based ('Audio' in media_type / 'Video' in media_type), so any other type value — e.g. an article, image gallery, or new content type — falls through. Not marked expected=True.

Source

Thrown at youtube_dl/extractor/rai.py:502

        media = self._download_json(
            'http://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-%s.html?json' % content_id,
            content_id, 'Downloading video JSON')

        title = media['name'].strip()

        media_type = media['type']
        if 'Audio' in media_type:
            relinker_info = {
                'formats': [{
                    'format_id': media.get('formatoAudio'),
                    'url': media['audioUrl'],
                    'ext': media.get('formatoAudio'),
                }]
            }
        elif 'Video' in media_type:
            relinker_info = self._extract_relinker_info(media['mediaUri'], content_id)
        else:
            raise ExtractorError('not a media file')

        self._sort_formats(relinker_info['formats'])

        thumbnails = []
        for image_type in ('image', 'image_medium', 'image_300'):
            thumbnail_url = media.get(image_type)
            if thumbnail_url:
                thumbnails.append({
                    'url': compat_urlparse.urljoin(url, thumbnail_url),
                })

        subtitles = self._extract_subtitles(url, media)

        info = {
            'id': content_id,
            'title': title,
            'description': strip_or_none(media.get('desc')),
            'thumbnails': thumbnails,

View on GitHub (pinned to 956b8c5855)

Solutions

  1. Make sure the URL points to an actual audio/video page on Rai, not an article or gallery.
  2. Update youtube-dl — new media types and resolver changes get patched in extractor updates.
  3. Inspect media['type'] for your id (download the resolved JSON) to see what the API thinks the content is.
  4. Pick the canonical media page URL from the Rai site UI and retry.
Defensive patterns

Strategy: validation

Validate before calling

# Pre-check the media type when you have the resolved JSON
is_media = ('Audio' in media.get('type', '')) or ('Video' in media.get('type', ''))

Type guard

def is_media_payload(media: dict) -> bool:
    t = media.get('type') or ''
    return 'Audio' in t or 'Video' in t

Try / catch

try:
    info = ydl.extract_info(url)
except ExtractorError as e:
    if 'not a media file' in str(e):
        find_media_page_url(url)

Prevention

When it happens

Trigger: The media JSON for the resolved id has a 'type' field containing neither 'Audio' nor 'Video' (e.g. 'photo', 'article', 'page'); typically reached when a content id resolves to a non-media resource or the resolver returns an unexpected payload shape.

Common situations: Urls for Rai news articles or photo pages rather than media pages; API changes introducing new type strings; id mix-ups where an article id is passed to the media resolver.

Related errors


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