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

Code before:
        response = self._download_json(f'https://goodgame.ru/api/4/users/{channel_name}/stream', channel_name)
        player_id = response['streamkey']

        formats, subtitles = [], {}
        if response.get('status'):
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                f'https://hls.goodgame.ru/manifest/{player_id}_master.m3u8',
                channel_name, 'mp4', live=True)
        else:
            self.raise_no_formats('User is offline', expected=True, video_id=channel_name)

        description_page = self._download_webpage(f'https://goodgame.ru/ajax/channel/tabs?id={player_id}', player_id)
        description = '\n'.join(description_page.splitlines()[21:-47])
        return {
            'id': player_id,
            'formats': formats,
            'subtitles': subtitles,
            'title': traverse_obj(response, ('title')),
            'channel': channel_name,
            'channel_id': str_or_none(traverse_obj(response, ('id'))),
            'channel_url': response.get('url'),
            'description': clean_html(description),
            'thumbnail': traverse_obj(response, ('preview')),
            'is_live': bool(formats),
            'view_count': int_or_none(response.get('viewers')),
            'age_limit': 18 if traverse_obj(response, ('adult')) else None,
        }


Review comment (security):
Let's write it like so, to simplify some calls and check more types:
```py
            'is_live': bool(formats),
            **traverse_obj(response, {
                'title': ('title', {str}),
                'channel': ('channelkey', {str}),
                'channel_id': ('id', {str_or_none}),
                'channel_url': ('link', {url_or_none}),
                'uploader': ('streamer', 'username', {str}),
                'uploader_id': ('streamer', 'id', {str_or_none}),
                'thumbnail': ('preview', {url_or_none}, {sanitize_url}),
                'concurrent_view_count': ('views', {int_or_none}),
                'channel_follower_count': ('followers', {int_or_none}),
                'age_limit': ('adult', {bool}, {lambda x: 18 if x else None}),
            }),
```
I've also added a couple more fields and renamed `view_count` to `concurrent_view_count` as that is more in line with other livestream extractors.

Code after:
        'only_matching': True,
    }, {
        'url': 'https://goodgame.ru/HeDoPa3yMeHue*',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        channel_name = self._match_id(url)
        response = self._download_json(f'https://goodgame.ru/api/4/users/{channel_name}/stream', channel_name)
        player_id = response['streamkey']

        formats, subtitles = [], {}
        if response.get('status'):
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                f'https://hls.goodgame.ru/manifest/{player_id}_master.m3u8',
                channel_name, 'mp4', live=True)
        else:
            self.raise_no_formats('User is offline', expected=True, video_id=channel_name)

        return {
            'id': player_id,
            'formats': formats,
            'subtitles': subtitles,
            'is_live': bool(formats),
            **traverse_obj(response, {
                'title': ('title', {str}),
                'channel': ('channelkey', {str}),
                'channel_id': ('id', {str_or_none}),
                'channel_url': ('link', {url_or_none}),
                'uploader': ('streamer', 'username', {str}),
                'uploader_id': ('streamer', 'id', {str_or_none}),
                'thumbnail': ('preview', {url_or_none}, {self._proto_relative_url}),
                'concurrent_view_count': ('viewers', {int_or_none}),
                'channel_follower_count': ('followers', {int_or_none}),
                'age_limit': ('adult', {bool}, {lambda x: 18 if x else None}),
            }),
        }