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

Code before:
    ExtractorError,
    traverse_obj,
    parse_iso8601,
)


class CHZZKLiveIE(InfoExtractor):
    IE_NAME = 'chzzk:live'
    _VALID_URL = r'https?://chzzk\.naver\.com/live/(?P<id>[^/#?]+)'
    _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')),

Review comment (suggestion):
```suggestion
        live_playback = self._parse_json(live_detail['livePlaybackJson'], channel_id)
```

Code after:
from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    float_or_none,
    int_or_none,
    parse_iso8601,
    url_or_none,
)
from ..utils.traversal import traverse_obj


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,