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

Code before:
        if not video_info.get('formattedIdMedia'):
            video_info = traverse_obj(
                video_info, ('freeTv', 'items', lambda _, v: v['key'] == video_id, {dict}),
                get_all=False, default={})

        video_stream_id = video_info.get('formattedIdMedia')
        if not video_stream_id:
            raise ExtractorError('Couldn\'t find video metadata, maybe this livestream is now offline', expected=True)

        stream_data = self._download_json(
            'https://services.radio-canada.ca/media/validation/v2/', video_id, query={
                'appCode': 'mpx',
                'connectionType': 'hd',
                'deviceType': 'ipad',
                'idMedia': video_stream_id,
                'multibitrate': 'true',
                'output': 'json',
                'tech': 'hls',
                'manifestType': 'desktop',
            })

        return {
            'formats': self._extract_m3u8_formats(stream_data['url'], video_id, 'mp4', live=True),
            'is_live': True,
            **traverse_obj(video_info, {
                'id': 'url',
                'title': 'title',
                'description': 'description',
                'thumbnail': ('images', 'card', 'url'),
                'timestamp': ('airDate', {parse_iso8601}),
            })
        }


Review comment (refactor):
an `id` needs to be returned, use the video_id. traversal is non-fatal and may not return a value for `id`
```suggestion
            'id': video_id,
            'formats': self._extract_m3u8_formats(stream_data['url'], video_id, 'mp4', live=True),
            'is_live': True,
            **traverse_obj(video_info, {
```

Code after:
        video_info = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['data']

        # Two types of metadata JSON
        if not video_info.get('formattedIdMedia'):
            video_info = traverse_obj(
                video_info, (('freeTv', ('streams', ...)), 'items', lambda _, v: v['key'] == video_id, {dict}),
                get_all=False, default={})

        video_stream_id = video_info.get('formattedIdMedia')
        if not video_stream_id:
            raise ExtractorError('Couldn\'t find video metadata, maybe this livestream is now offline', expected=True)

        stream_data = self._download_json(
            'https://services.radio-canada.ca/media/validation/v2/', video_id, query={
                'appCode': 'mpx',
                'connectionType': 'hd',
                'deviceType': 'ipad',
                'idMedia': video_stream_id,
                'multibitrate': 'true',
                'output': 'json',
                'tech': 'hls',
                'manifestType': 'desktop',
            })

        return {
            'id': video_id,
            'formats': self._extract_m3u8_formats(stream_data['url'], video_id, 'mp4', live=True),
            'is_live': True,
            **traverse_obj(video_info, {
                'title': 'title',
                'description': 'description',
                'thumbnail': ('images', 'card', 'url'),
                'timestamp': ('airDate', {parse_iso8601}),
            })
        }