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

Code before:
            'id': '2458',
            'ext': 'mp4',
            'title': '첫 방송',
            'channel': '강지',
            'channel_id': 'b5ed5db484d04faf4d150aedd362f34b',
            'channel_is_verified': True,
            'thumbnail': r're:^https?://.*\.jpg$',
            'duration': 4433,
            'timestamp': 1703307460.214,
            'upload_date': '20231223',
            'view_count': int,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_meta = self._download_json(
            f'https://api.chzzk.naver.com/service/v3/videos/{video_id}', video_id,
            note='Downloading video info', errnote='Unable to download video info')['content']
        video_status = video_meta.get('vodStatus')
        video_live_date = video_meta.get('liveOpenDate')
        if video_live_date:
            live_status = 'was_live'
        else:
            live_status = 'not_live'

        if video_status == 'UPLOAD':
            playback = self._parse_json(video_meta.get('liveRewindPlaybackJson'), video_id)
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                traverse_obj(playback, ('media', 0, 'path')), video_id,
                note='Downloading video playback', errnote='Unable to download video playback')
        elif video_status == 'ABR_HLS':
            formats, subtitles = self._extract_mpd_formats_and_subtitles(
                f'https://apis.naver.com/neonplayer/vodplay/v1/playback/{video_meta.get("videoId")}', video_id,
                query={
                    'key': video_meta['inKey'],
                    'env': 'real',
                    'lc': 'en_US',
                    'cpl': 'en_US',
                }, note='Downloading video playback', errnote='Unable to download video playback')
        else:
            self.raise_no_formats(f'Unknown video status detected: "{video_status}"',
                                  expected=True, video_id=video_id)
            formats = []
            subtitles = {}
            if live_status == 'was_live':
                live_status = 'post_live'
        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,

Review comment (suggestion):
- let's move `video_status` to the bottom here / to the beginning of the next code block since it's only relevant to that block
- is `liveOpenDate` useful metadata? should we return it is `release_timestamp` or something? if not, let's condense this:
```suggestion

        live_status = 'was_live' is video_meta.get('liveOpenDate') else 'not_live'
        video_status = video_meta.get('vodStatus')
```

Code after:
            'id': '2458',
            'ext': 'mp4',
            'title': '첫 방송',
            'channel': '강지',
            'channel_id': 'b5ed5db484d04faf4d150aedd362f34b',
            'channel_is_verified': True,
            'thumbnail': r're:^https?://.*\.jpg$',
            'duration': 4433,
            'timestamp': 1703307460.214,
            'upload_date': '20231223',
            'view_count': int,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_meta = self._download_json(
            f'https://api.chzzk.naver.com/service/v3/videos/{video_id}', video_id,
            note='Downloading video info', errnote='Unable to download video info')['content']

        live_status = 'was_live' if video_meta.get('liveOpenDate') else 'not_live'
        video_status = video_meta.get('vodStatus')
        if video_status == 'UPLOAD':
            playback = self._parse_json(video_meta['liveRewindPlaybackJson'], video_id)
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                playback['media'][0]['path'], video_id, 'mp4', m3u8_id='hls')
        elif video_status == 'ABR_HLS':
            formats, subtitles = self._extract_mpd_formats_and_subtitles(
                f'https://apis.naver.com/neonplayer/vodplay/v1/playback/{video_meta["videoId"]}',
                video_id, query={
                    'key': video_meta['inKey'],
                    'env': 'real',
                    'lc': 'en_US',
                    'cpl': 'en_US',
                })
        else:
            self.raise_no_formats(
                f'Unknown video status detected: "{video_status}"', expected=True, video_id=video_id)
            formats, subtitles = [], {}
            live_status = 'post_live' if live_status == 'was_live' else None

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            'live_status': live_status,
            **traverse_obj(video_meta, {
                'title': ('videoTitle', {str}),
                'thumbnail': ('thumbnailImageUrl', {url_or_none}),
                'timestamp': ('publishDateAt', {functools.partial(float_or_none, scale=1000)}),
                'view_count': ('readCount', {int_or_none}),