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

Code before:
import functools

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    OnDemandPagedList,
    UserNotLive,
    int_or_none,
    parse_iso8601,
    str_or_none,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class NuumBaseIE(InfoExtractor):

    def _call_api(self, path, video_id, description, query={}):
        response = self._download_json(
            f'https://nuum.ru/api/v2/{path}', video_id, query=query,
            note=f'Downloading {description} metadata',
            errnote=f'Unable to download {description} metadata')
        if error := response.get('error'):
            raise ExtractorError(f'API returned error: {error!r}')
        return response.get('result')

    def _get_channel_info(self, channel_name):
        return self._call_api(
            'broadcasts/public', video_id=channel_name, description='channel',
            query={
                'with_extra': 'true',
                'channel_name': channel_name,
                'with_deleted': 'true',
            })

    def _parse_video_data(self, container):
        stream = traverse_obj(container, ('media_container_streams', 0))
        media = traverse_obj(stream, ('stream_media', 0))
        media_url = traverse_obj(media, (
            'media_meta', ('media_archive_url', 'media_url'), {url_or_none}), get_all=False)

        return media_url, {
            'id': str(container['media_container_id']),
            'is_live': media.get('media_status') == 'RUNNING',
            **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}),

Review comment (suggestion):
would be worse to return `None` than `KeyError` here
```suggestion
        return response['result']
```

Code after:
import functools

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    OnDemandPagedList,
    UserNotLive,
    filter_dict,
    int_or_none,
    parse_iso8601,
    str_or_none,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class NuumBaseIE(InfoExtractor):
    def _call_api(self, path, video_id, description, query={}):
        response = self._download_json(
            f'https://nuum.ru/api/v2/{path}', video_id, query=query,
            note=f'Downloading {description} metadata',
            errnote=f'Unable to download {description} metadata')
        if error := response.get('error'):
            raise ExtractorError(f'API returned error: {error!r}')
        return response['result']

    def _get_channel_info(self, channel_name):
        return self._call_api(
            'broadcasts/public', video_id=channel_name, description='channel',
            query={
                'with_extra': 'true',
                'channel_name': channel_name,
                'with_deleted': 'true',
            })

    def _parse_video_data(self, container, extract_formats=True):
        stream = traverse_obj(container, ('media_container_streams', 0, {dict})) or {}
        media = traverse_obj(stream, ('stream_media', 0, {dict})) or {}
        media_url = traverse_obj(media, (
            'media_meta', ('media_archive_url', 'media_url'), {url_or_none}), get_all=False)

        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({