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

Code before:
            'is_live': True,
            'formats': formats,
            'subtitles': subtitles,
        }


class CHZZKVideoIE(InfoExtractor):
    IE_NAME = 'chzzk:video'
    _VALID_URL = r'https?://chzzk\.naver\.com/video/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://chzzk.naver.com/video/1754',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        NS_MAP = {
            'nvod': "urn:naver:vod:2020",
            '': "urn:mpeg:dash:schema:mpd:2011",
        }

        video_id = self._match_id(url)
        video_meta_response = self._download_json(
            f'https://api.chzzk.naver.com/service/v1/videos/{video_id}', video_id,
            note='Downloading video info',
            errnote='Unable to download video info')
        video_meta = video_meta_response.get('content')
        vod_id = video_meta.get('videoId')
        in_key = video_meta.get('inKey')
        playback_xml = self._download_xml(
            f'https://apis.naver.com/neonplayer/vodplay/v1/playback/{vod_id}', video_id,
            query={
                'key': in_key,
                'env': 'real',
                'lc': 'en_US',
                'cpl': 'en_US',
            },
            note='Downloading video playback',
            errnote='Unable to download video playback')

        thumbnails = []
        i = 0
        for source in playback_xml.iterfind(
            './Period/SupplementalProperty/nvod:Thumbnails/nvod:ThumbnailSet/nvod:Thumbnail/nvod:Source',
            NS_MAP,
        ):
            thumbnails.append({'id': str(i), 'url': source.text.split('?')[0]})
            i += 1

        formats, subtitles = self._parse_mpd_formats_and_subtitles(playback_xml)

        return {

Review comment (suggestion):
Already needs to be updated to v2. Getting `'content'` should also be fatal.
```suggestion
        video_meta = self._download_json(
            f'https://api.chzzk.naver.com/service/v2/videos/{video_id}', video_id,
            note='Downloading video info', errnote='Unable to download video info')['content']
```


Code after:
        formats, subtitles = [], {}
        for media in traverse_obj(live_playback, ('media', lambda _, v: url_or_none(v['path']))):
            is_low_latency = media.get('mediaId') == 'LLHLS'
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                media['path'], channel_id, 'mp4', fatal=False, live=True,
                m3u8_id='hls-ll' if is_low_latency else 'hls')
            for f in fmts:
                if is_low_latency:
                    f['source_preference'] = -2
                if '-afragalow.stream-audio.stream' in f['format_id']:
                    f['quality'] = -2
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        return {
            'id': channel_id,
            'is_live': True,
            'formats': formats,
            'subtitles': subtitles,
            'thumbnails': thumbnails,
            **traverse_obj(live_detail, {
                'title': ('liveTitle', {str}),
                'timestamp': ('openDate', {functools.partial(parse_iso8601, delimiter=' ')}),
                'concurrent_view_count': ('concurrentUserCount', {int_or_none}),
                'view_count': ('accumulateCount', {int_or_none}),
                'channel': ('channel', 'channelName', {str}),
                'channel_id': ('channel', 'channelId', {str}),
                'channel_is_verified': ('channel', 'verifiedMark', {bool}),
            }),
        }


class CHZZKVideoIE(InfoExtractor):
    IE_NAME = 'chzzk:video'
    _VALID_URL = r'https?://chzzk\.naver\.com/video/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://chzzk.naver.com/video/1754',
        'md5': 'b0c0c1bb888d913b93d702b1512c7f06',
        'info_dict': {
            'id': '1754',
            'ext': 'mp4',
            'title': '치지직 테스트 방송',
            'channel': '침착맨',
            'channel_id': 'bb382c2c0cc9fa7c86ab3b037fb5799c',
            'channel_is_verified': False,
            'thumbnail': r're:^https?://.*\.jpg$',
            'duration': 15577,
            'timestamp': 1702970505.417,
            'upload_date': '20231219',
            'view_count': int,
        },