Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/digiteka.py (Python)

Code before:
    _EMBED_REGEX = [r'<(?:iframe|script)[^>]+src=["\'](?P<url>(?:https?:)?//(?:www\.)?ultimedia\.com/deliver/(?:generic|musique)(?:/[^/]+)*/(?:src|article)/[\d+a-z]+)']
    _TESTS = [{
        'url': 'https://www.ultimedia.com/default/index/videogeneric/id/3x5x55k',
        'info_dict': {
            'id': '3x5x55k',
            'ext': 'mp4',
            'title': 'Il est passionné de DS',
            'thumbnail': r're:^https?://.*\.jpg',
            'duration': 89,
            'upload_date': '20251012',
            'timestamp': 1760285363,
            'uploader_id': '3pz33',
        },
        'params': {'skip_download': True},
    }]

    def _real_extract(self, url):
        mobj = self._match_valid_url(url)
        video_id = mobj.group('id')

        IFRAME_MD_ID = '01836272'   # One static ID working for Ultimedia iframes

        api_url = f'https://www.ultimedia.com/player/getConf/{IFRAME_MD_ID}/1/{video_id}'

        conf_data = self._download_json(
            api_url, video_id, note='Downloading player configuration')

        video_info = conf_data.get('video')
        if not video_info:
            raise ExtractorError('Failed to retrieve video information from API.', expected=True)

        title = video_info['title']
        formats = []
        media_sources = video_info.get('media_sources', {})

        hls_sources = media_sources.get('hls', {})
        for format_id, hls_url in hls_sources.items():
            if not hls_url:
                continue

            height_str = format_id.split('_')[-1]
            height = int(height_str) if height_str.isdigit() else None

            formats.append({
                'url': hls_url,
                'format_id': f'hls-{height_str}',
                'height': height,
                'protocol': 'm3u8_native',
                'ext': 'mp4',
            })


Review comment (suggestion):
Can just inline this and make it fatal. If the API doesn't return a video, there is nothing useful we can do anyway
```suggestion
        video_info = self._download_json(
            f'https://www.ultimedia.com/player/getConf/{IFRAME_MD_ID}/1/{video_id}', video_id,
            note='Downloading player configuration')['video']
```

Code after:
        )/(?P<id>[\d+a-z]+)'''
    _EMBED_REGEX = [r'<(?:iframe|script)[^>]+src=["\'](?P<url>(?:https?:)?//(?:www\.)?ultimedia\.com/deliver/(?:generic|musique)(?:/[^/]+)*/(?:src|article)/[\d+a-z]+)']
    _TESTS = [{
        'url': 'https://www.ultimedia.com/default/index/videogeneric/id/3x5x55k',
        'info_dict': {
            'id': '3x5x55k',
            'ext': 'mp4',
            'title': 'Il est passionné de DS',
            'thumbnail': r're:^https?://.*\.jpg',
            'duration': 89,
            'upload_date': '20251012',
            'timestamp': 1760285363,
            'uploader_id': '3pz33',
        },
        'params': {'skip_download': True},
    }]
    _IFRAME_MD_ID = '01836272'   # One static ID working for Ultimedia iframes

    def _real_extract(self, url):
        video_id = self._match_id(url)

        video_info = self._download_json(
            f'https://www.ultimedia.com/player/getConf/{self._IFRAME_MD_ID}/1/{video_id}', video_id,
            note='Downloading player configuration')['video']

        formats = []
        subtitles = {}

        if hls_url := traverse_obj(video_info, ('media_sources', 'hls', 'hls_auto', {url_or_none})):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        for format_id, mp4_url in traverse_obj(video_info, ('media_sources', 'mp4', {dict.items}, ...)):
            if not mp4_url:
                continue
            formats.append({
                'url': mp4_url,
                'format_id': format_id,
                'height': int_or_none(format_id.partition('_')[2]),
                'ext': 'mp4',
            })

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(video_info, {
                'title': ('title', {str}),
                'thumbnail': ('image', {url_or_none}),