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

Code before:
            'description': 'md5:03b5238d6549f4ea1fddadf69b5e0b58',
            'upload_date': '20230323',
            'timestamp': 1679612400,
            'thumbnail': r're:^https?://.*\.(?:jpg|png)',
        },
        'params': {'skip_download': 'm3u8'}
    }, {
        'url': 'https://elevensports.com/view/event/clhpyd53b06160jez74qhgkmf',
        'md5': 'c0958d9ff90e4503a75544358758921d',
        'info_dict': {
            'id': 'clhpyd53b06160jez74qhgkmf',
            'title': 'AJNLF vs ARRAF',
            'ext': 'mp4',
            'description': 'md5:c8c5e75c78f37c6d15cd6c475e43a8c1',
            'upload_date': '20230521',
            'timestamp': 1684684800,
            'thumbnail': r're:^https?://.*\.(?:jpg|png)',
        },
        'params': {'skip_download': 'm3u8'}
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        nextjs_info = self._search_nextjs_data(webpage, video_id)
        event_id = traverse_obj(nextjs_info, ('props', 'pageProps', 'event', 'mclsEventId'), default={})
        event_data = self._download_json(
            f'https://mcls-api.mycujoo.tv/bff/events/v1beta1/{event_id}', video_id, headers={"Authorization": "Bearer FBVKACGN37JQC5SFA0OVK8KKSIOP153G"})
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            event_data['streams'][0]['full_url'], video_id, 'mp4', m3u8_id='hls', fatal=False
        )

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(event_data, {
                'title': ('title', {str}),
                'description': ('description', {str}),
                'upload_date': ('start_time', {unified_strdate}),
                'timestamp': ('start_time', {parse_iso8601}),
                'thumbnail': ('thumbnail_url', {url_or_none}),
            }),
        }


Review comment (refactor):
Since we can't extract any formats or any metadata without `event_id`, it can be fatal.
And having it default to `{}` doesn't make sense.
```suggestion
        event_id = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['event']['mclsEventId']
```

Code after:
            'upload_date': '20230323',
            'timestamp': 1679612400,
            'thumbnail': r're:^https?://.*\.(?:jpg|png)',
        },
        'params': {'skip_download': 'm3u8'}
    }, {
        'url': 'https://elevensports.com/view/event/clhpyd53b06160jez74qhgkmf',
        'md5': 'c0958d9ff90e4503a75544358758921d',
        'info_dict': {
            'id': 'clhpyd53b06160jez74qhgkmf',
            'title': 'AJNLF vs ARRAF',
            'ext': 'mp4',
            'description': 'md5:c8c5e75c78f37c6d15cd6c475e43a8c1',
            'upload_date': '20230521',
            'timestamp': 1684684800,
            'thumbnail': r're:^https?://.*\.(?:jpg|png)',
        },
        'params': {'skip_download': 'm3u8'}
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        event_id = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['event']['mclsEventId']
        event_data = self._download_json(
            f'https://mcls-api.mycujoo.tv/bff/events/v1beta1/{event_id}', video_id,
            headers={'Authorization': 'Bearer FBVKACGN37JQC5SFA0OVK8KKSIOP153G'})
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            event_data['streams'][0]['full_url'], video_id, 'mp4', m3u8_id='hls')

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(event_data, {
                'title': ('title', {str}),
                'description': ('description', {str}),
                'timestamp': ('start_time', {parse_iso8601}),
                'thumbnail': ('thumbnail_url', {url_or_none}),
            }),
        }