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

Code before:
                'ext': 'mp4',
                'id': 'the-epicenter-of-ai-is-in-seattle-says-jim-cramer',
                'thumbnail': 'https://image.cnbcfm.com/api/v1/image/107345486-Screenshot_2023-12-08_at_70339_PM.png?v=1702080248',
                'thumbnails': [
                    {
                        'url': 'https://image.cnbcfm.com/api/v1/image/107345486-Screenshot_2023-12-08_at_70339_PM.png?v=1702080248'
                    }
                ],
                'timestamp': 1702080535,
                'title': 'The epicenter of AI is in Seattle, says Jim Cramer',
                'upload_date': '20231208',
            },
            'expected_warnings': ['Unable to download f4m manifest'],
        },
    ]

    def _real_extract(self, url):
        display_id = self._match_valid_url(url).group('id')
        webpage = self._download_webpage(url, display_id)
        metadata = json.loads(
            self._html_search_regex(
                r'window\.__s_data=(\{.*?\});', webpage, 'video JSON data.'))

        link = traverse_obj(
            metadata,
            ('page', 'page', 'layout', 1, 'columns', 0, 'modules', 0, 'data', 'encodings', 0, 'url'), expected_type=url_or_none)

        upload_date = traverse_obj(
            metadata,
            ('page', 'page', 'layout', 1, 'columns', 0, 'modules', 0, 'data', 'uploadDate'))

        return {
            'author': self._html_search_regex(
                r'<meta name="parsely-author" content="([^<]+)"',
                webpage,
                'video author',
                default=None),
            'channel': self._html_search_regex(
                r'<div class="ClipPlayer-clipPlayerIntroSection"><[^>]*>([^<]+)<',
                webpage,
                'channel name',
                fatal=False),
            'formats': self._extract_akamai_formats(link, display_id),
            'id': display_id,
            'upload_date': unified_strdate(upload_date) if upload_date else None,
            'url': link,
            **traverse_obj(
                self._search_json_ld(webpage, display_id, default={}),
                {
                    'title': 'title',
                    'description': 'description',

Review comment (suggestion):
I would not hardcode the position in the array:
```suggestion
        player_data = traverse_obj(data, (
            'page', 'page', 'layout', ..., 'columns', ..., 'modules',
            lambda _, v: v['name'] == 'clipPlayer', 'data', {dict}), get_all=False)
```

Code after:
            'thumbnail': 'https://image.cnbcfm.com/api/v1/image/107345486-Screenshot_2023-12-08_at_70339_PM.png?v=1702080248',
            'timestamp': 1702080535,
            'title': 'The epicenter of AI is in Seattle, says Jim Cramer',
            'release_timestamp': 1702077347,
            'modified_timestamp': 1702080535,
            'release_date': '20231208',
            'upload_date': '20231209',
            'modified_date': '20231209',
        },
        'expected_warnings': ['Unable to download f4m manifest'],
    }]

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        data = self._search_json(r'window\.__s_data=', webpage, 'video data', display_id)

        player_data = traverse_obj(data, (
            'page', 'page', 'layout', ..., 'columns', ..., 'modules',
            lambda _, v: v['name'] == 'clipPlayer', 'data', {dict}), get_all=False)

        return {
            'id': display_id,
            'display_id': display_id,
            'formats': self._extract_akamai_formats(player_data['playbackURL'], display_id),
            **self._search_json_ld(webpage, display_id, fatal=False),
            **traverse_obj(player_data, {
                'id': ('id', {str_or_none}),
                'title': ('title', {str}),
                'description': ('description', {str}),
                'author': ('author', ..., 'name', {str}),
                'timestamp': ('datePublished', {parse_iso8601}),
                'release_timestamp': ('uploadDate', {parse_iso8601}),
                'modified_timestamp': ('dateLastPublished', {parse_iso8601}),
                'thumbnail': ('thumbnail', {url_or_none}),
                'duration': ('duration', {int_or_none}),
                'channel': ('section', 'title', {str}),
            }, get_all=False),
        }