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

Code before:
    _TESTS = [{
        'url': 'https://chzzk.naver.com/live/c68b8ef525fb3d2fa146344d84991753',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        channel_id = self._match_id(url)
        live_detail_response = self._download_json(
            f'https://api.chzzk.naver.com/service/v1/channels/{channel_id}/live-detail', channel_id,
            note='Downloading channel info',
            errnote='Unable to download channel info')
        live_detail = live_detail_response.get('content')

        if live_detail.get('status') == 'CLOSE':
            raise ExtractorError('The channel is not currently live', expected=True)

        live_playback = self._parse_json(live_detail.get('livePlaybackJson'), channel_id)

        thumbnails = []
        thumbnail_template = traverse_obj(live_playback, ('thumbnail', 'snapshotThumbnailTemplate'))
        for width in traverse_obj(live_playback, ('thumbnail', 'types')):
            thumbnails.append({
                'id': width,
                'url': thumbnail_template.replace('{type}', width),
                'width': int(width),
            })

        formats, subtitles = [], {}
        for media in live_playback.get('media'):
            media_url = media.get('path')
            fmts, subs = self._extract_m3u8_formats_and_subtitles(media_url, channel_id, 'mp4')
            if media.get('mediaId') == 'LLHLS':
                for fmt in fmts:
                    fmt['format_id'] += '-ll'
            formats.extend(fmts)
            self._merge_subtitles(subtitles, subs)

        return {
            'id': str(channel_id),
            'title': live_detail.get('liveTitle'),
            'thumbnails': thumbnails,
            'timestamp': parse_iso8601(live_detail.get('openDate')),
            'view_count': live_detail.get('concurrentUserCount'),
            'channel': traverse_obj(live_detail, ('channel', 'channelName')),
            'channel_id': traverse_obj(live_detail, ('channel', 'channelId')),
            'channel_is_verified': traverse_obj(live_detail, ('channel', 'verifiedMark')),
            'is_live': True,
            'formats': formats,
            'subtitles': subtitles,
        }


Review comment (suggestion):
```suggestion
        thumbnail_template = traverse_obj(
            live_playback, ('thumbnail', 'snapshotThumbnailTemplate', {url_or_none}))
        if thumbnail_template:
            for width in traverse_obj(live_playback, ('thumbnail', 'types', ..., {str})):
                thumbnails.append({
                    'id': width,
                    'url': thumbnail_template.replace('{type}', width),
                    'width': int_or_none(width),
                })
```

Code after:


class CHZZKLiveIE(InfoExtractor):
    IE_NAME = 'chzzk:live'
    _VALID_URL = r'https?://chzzk\.naver\.com/live/(?P<id>[\da-f]+)'
    _TESTS = [{
        'url': 'https://chzzk.naver.com/live/c68b8ef525fb3d2fa146344d84991753',
        'info_dict': {
            'id': 'c68b8ef525fb3d2fa146344d84991753',
            'ext': 'mp4',
            'title': str,
            'channel': '진짜도현',
            'channel_id': 'c68b8ef525fb3d2fa146344d84991753',
            'channel_is_verified': False,
            'thumbnail': r're:^https?://.*\.jpg$',
            'timestamp': 1705510344,
            'upload_date': '20240117',
            'live_status': 'is_live',
            'view_count': int,
            'concurrent_view_count': int,
        },
        'skip': 'The channel is not currently live',
    }]

    def _real_extract(self, url):
        channel_id = self._match_id(url)
        live_detail = self._download_json(
            f'https://api.chzzk.naver.com/service/v2/channels/{channel_id}/live-detail', channel_id,
            note='Downloading channel info', errnote='Unable to download channel info')['content']

        if live_detail.get('status') == 'CLOSE':
            raise ExtractorError('The channel is not currently live', expected=True)

        live_playback = self._parse_json(live_detail['livePlaybackJson'], channel_id)

        thumbnails = []
        thumbnail_template = traverse_obj(
            live_playback, ('thumbnail', 'snapshotThumbnailTemplate', {url_or_none}))
        if thumbnail_template and '{type}' in thumbnail_template:
            for width in traverse_obj(live_playback, ('thumbnail', 'types', ..., {str})):
                thumbnails.append({
                    'id': width,
                    'url': thumbnail_template.replace('{type}', width),
                    'width': int_or_none(width),
                })

        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,