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

Code before:

        m3u8_url, info = self._parse_video_data(video_data)

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            m3u8_url, video_id, 'mp4', live=info['is_live'])
        info.update({
            'formats': formats,
            'subtitles': subtitles,
        })
        return info


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 _real_extract(self, url):
        channel = self._match_id(url)
        channel_info = self._get_channel_info(channel)
        if traverse_obj(channel_info, ('channel', 'channel_is_live')) is False:
            raise UserNotLive(video_id=channel)

        m3u8_url, metadata = self._parse_video_data(channel_info['media_container'])
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, channel, 'mp4', live=True)
        return {
            'formats': formats,
            'subtitles': subtitles,
            'webpage_url': f'https://nuum.ru/streams/{metadata["id"]}',
            'extractor_key': NuumMediaIE.ie_key(),
            'extractor': NuumMediaIE.IE_NAME,
            **metadata,
        }


class NuumTabIE(NuumBaseIE):
    IE_NAME = 'nuum:tab'
    _VALID_URL = r'https?://nuum\.ru/channel/(?P<id>[^/#?]+)/(?P<type>streams|videos|clips)'
    _TESTS = [{
        'url': 'https://nuum.ru/channel/dankon_/clips',
        'info_dict': {
            'id': 'dankon__clips',
            'title': 'Dankon_',
        },
        'playlist_mincount': 29,
    }, {
        'url': 'https://nuum.ru/channel/dankon_/videos',
        'info_dict': {

Review comment (refactor):
I'd just do this since we don't want to continue extraction unless truthy
```suggestion
        if not traverse_obj(channel_info, ('channel', 'channel_is_live')):
```

Code after:
            'concurrent_view_count': int,
            'channel_id': '3320',
            'channel': 'Misalelik',
            'duration': 41,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_data = self._call_api(f'media-containers/{video_id}', video_id, 'media')

        return self._parse_video_data(video_data)


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 _real_extract(self, url):
        channel = self._match_id(url)
        channel_info = self._get_channel_info(channel)
        if traverse_obj(channel_info, ('channel', 'channel_is_live')) is False:
            raise UserNotLive(video_id=channel)

        info = self._parse_video_data(channel_info['media_container'])
        return {
            'webpage_url': f'https://nuum.ru/streams/{info["id"]}',
            'extractor_key': NuumMediaIE.ie_key(),
            'extractor': NuumMediaIE.IE_NAME,
            **info,
        }


class NuumTabIE(NuumBaseIE):
    IE_NAME = 'nuum:tab'
    _VALID_URL = r'https?://nuum\.ru/channel/(?P<id>[^/#?]+)/(?P<type>streams|videos|clips)'
    _TESTS = [{
        'url': 'https://nuum.ru/channel/dankon_/clips',
        'info_dict': {
            'id': 'dankon__clips',
            'title': 'Dankon_',
        },
        'playlist_mincount': 29,
    }, {
        'url': 'https://nuum.ru/channel/dankon_/videos',
        'info_dict': {
            'id': 'dankon__videos',