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

Code before:
    def _real_extract(self, url):
        container = self._get_container(url)
        stream = traverse_obj(container, ('media_container_streams', 0))
        media = try_get(stream, lambda x: x['stream_media'][0])
        if not media:
            raise ExtractorError('Cannot extract media data', expected=True)
        media_meta = media.get('media_meta')
        media_url, is_live = self._get_media_url(media_meta)
        video_id = media.get('media_id') or container.get('media_container_id')
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(media_url, video_id, 'mp4')
        return {
            'id': str(video_id),
            'title': container.get('media_container_name') or self._og_search_title(self._download_webpage(url, video_id)),
            'description': container.get('media_container_description'),
            'thumbnails': self._extract_thumbnails(media_meta.get('media_preview_images' if is_live else 'media_preview_archive_images')),
            'timestamp': parse_iso8601(container.get('created_at')),
            'view_count': int_or_none(stream.get('stream_current_viewers' if is_live else 'stream_total_viewers')),
            'is_live': is_live,
            'formats': formats,
            'subtitles': subtitles,
        }


class NuumLiveIE(NuumBaseIE):
    IE_NAME = 'nuum:live'
    _VALID_URL = r'https?://nuum\.ru/channel/(?P<id>[^/#?]+)'
    _TESTS = [{
        'url': 'https://nuum.ru/channel/mts_live',
        'only_matching': True,
    }]

    def _get_container(self, url):
        channel_name = self._match_id(url)
        broadcast = self._fetch(
            'broadcasts/public', video_id=channel_name, description='channel',
            query={
                'with_extra': 'true',
                'channel_name': channel_name,
                'with_deleted': 'true',
            }
        )
        if not traverse_obj(broadcast, ('channel', 'channel_is_live')):
            raise ExtractorError('The channel is not currently live', expected=True)
        return broadcast.get('media_container')

    def _get_media_url(self, media_meta):
        return media_meta['media_url'], True


class NuumStreamIE(NuumBaseIE):
    IE_NAME = 'nuum:stream'

Review comment (refactor):
I think attempting to download the livestreams here is unexpected.
In my opinion, it would make more sense to handle this like the YouTube extractor:
`https://nuum.ru/channel/channel_name` - return all the tabs (the links below)
`https://nuum.ru/channel/channel_name/streams` - return all currently ongoing streams (not sure if there can be multiple at once)
`https://nuum.ru/channel/channel_name/videos` - return all videos
`https://nuum.ru/channel/channel_name/clips` - return all clips

You don't need to implement all that if you don't want to.

Code after:

        video_id = str(container['media_container_id'])
        is_live = media.get('media_status') == 'RUNNING'

        formats, subtitles = None, None
        if extract_formats:
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                media_url, video_id, 'mp4', live=is_live)

        return filter_dict({
            'id': video_id,
            'is_live': is_live,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(container, {
                'title': ('media_container_name', {str}),
                'description': ('media_container_description', {str}),
                'timestamp': ('created_at', {parse_iso8601}),
                'channel': ('media_container_channel', 'channel_name', {str}),
                'channel_id': ('media_container_channel', 'channel_id', {str_or_none}),
            }),
            **traverse_obj(stream, {
                'view_count': ('stream_total_viewers', {int_or_none}),
                'concurrent_view_count': ('stream_current_viewers', {int_or_none}),
            }),
            **traverse_obj(media, {
                'duration': ('media_duration', {int_or_none}),
                'thumbnail': ('media_meta', ('media_preview_archive_url', 'media_preview_url'), {url_or_none}),
            }, get_all=False),
        })


class NuumMediaIE(NuumBaseIE):
    IE_NAME = 'nuum:media'
    _VALID_URL = r'https?://nuum\.ru/(?:streams|videos|clips)/(?P<id>[\d]+)'
    _TESTS = [{
        'url': 'https://nuum.ru/streams/1592713-7-days-to-die',
        'only_matching': True,
    }, {
        'url': 'https://nuum.ru/videos/1567547-toxi-hurtz',
        'md5': 'f1d9118a30403e32b702a204eb03aca3',
        'info_dict': {
            'id': '1567547',
            'ext': 'mp4',
            'title': 'Toxi$ - Hurtz',
            'description': '',
            'timestamp': 1702631651,
            'upload_date': '20231215',
            'thumbnail': r're:^https?://.+\.jpg',
            'view_count': int,
            'concurrent_view_count': int,