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

Code before:
        },
    }, {
        'url': 'https://edition.cnn.com/2024/06/11/politics/video/inmates-vote-jail-nevada-murray-dnt-ac360-digvid',
        'info_dict': {
            'id': 'inmates-vote-jail-nevada-murray-dnt-ac360-digvid-1563291-1920x1080_8000k',
            'ext': 'mp4',
            'direct': True,
            'title': 'inmates-vote-jail-nevada-murray-dnt-ac360-digvid-1563291-1920x1080_8000k',
            'timestamp': 1718158370.0,
            'upload_date': '20240612',
        },
    }, {
        'url': 'https://www.cnn.com/2024/06/11/style/video/king-charles-portrait-vandalized-activists-foster-intl-digvid',
        'info_dict': {
            'id': 'king-charles-portrait-vandalized-activists-foster-intl-digvid-1562674-1920x1080_8000k',
            'ext': 'mp4',
            'direct': True,
            'title': 'king-charles-portrait-vandalized-activists-foster-intl-digvid-1562674-1920x1080_8000k',
            'timestamp': 1718116155.0,
            'upload_date': '20240611',
        },
    }]

    def _real_extract(self, url):
        webpage = self._download_webpage(url, url_basename(url))
        cnn_url = self._search_json_ld(webpage, url_basename(url)).get('url')
        if (cnn_url):
            return self.url_result(cnn_url, 'Generic')
        return self.url_result(url, CNNIE)


class CNNIndonesiaIE(InfoExtractor):
    _VALID_URL = r'https?://www\.cnnindonesia\.com/[\w-]+/(?P<upload_date>\d{8})\d+-\d+-(?P<id>\d+)/(?P<display_id>[\w-]+)'
    _TESTS = [{
        'url': 'https://www.cnnindonesia.com/ekonomi/20220909212635-89-845885/alasan-harga-bbm-di-indonesia-masih-disubsidi',
        'info_dict': {
            'id': '845885',
            'ext': 'mp4',
            'description': 'md5:e7954bfa6f1749bc9ef0c079a719c347',
            'upload_date': '20220909',
            'title': 'Alasan Harga BBM di Indonesia Masih Disubsidi',
            'timestamp': 1662859088,
            'duration': 120.0,
            'thumbnail': r're:https://akcdn\.detik\.net\.id/visual/2022/09/09/thumbnail-ekopedia-alasan-harga-bbm-disubsidi_169\.jpeg',
            'tags': ['ekopedia', 'subsidi bbm', 'subsidi', 'bbm', 'bbm subsidi', 'harga pertalite naik'],
            'age_limit': 0,
            'release_timestamp': 1662859088,
            'release_date': '20220911',
            'uploader': 'Asfahan Yahsyi',
        },
    }, {

Review comment (suggestion):
If there's no result this can raise: give it a default:
```suggestion
        cnn_url = self._search_json_ld(webpage, url_basename(url), default={}).get('url')
```

Code after:
                'thumbnail': 'https://media.cnn.com/api/v1/images/stellar/prod/harris-20241016234916617.jpg?c=original',
                'duration': 173.0,
                'timestamp': 1729122182,
                'upload_date': '20241016',
                'modified_timestamp': 1729194706,
                'modified_date': '20241017',
            },
            'params': {'format': 'direct'},
        }, {
            'md5': '11604ab4af83b650826753f1ccb8ecff',
            'info_dict': {
                'id': 'med04507d8ca3da827001f63d22af321ec29c7d97b',
                'ext': 'mp4',
                'title': '\'Wise\': Buttigieg on Harris\' handling of interview question about gender transition surgery',
                'display_id': 'pete-buttigieg-harris-fox-newssrc-digvid',
                'description': 'md5:602a8a7e853ed5e574acd3159428c98e',
                'thumbnail': 'https://media.cnn.com/api/v1/images/stellar/prod/buttigieg-20241017040412074.jpg?c=original',
                'duration': 145.0,
                'timestamp': 1729137765,
                'upload_date': '20241017',
                'modified_timestamp': 1729138184,
                'modified_date': '20241017',
            },
            'params': {'format': 'direct'},
        }],
    }]

    def _real_extract(self, url):
        display_id = self._match_valid_url(url).group('display_id')
        webpage = self._download_webpage(url, display_id)
        app_id = traverse_obj(
            self._search_json(r'window\.env\s*=', webpage, 'window env', display_id, default={}),
            ('TOP_AUTH_SERVICE_APP_ID', {str}))

        entries = []
        for player_data in traverse_obj(webpage, (
                {find_elements(tag='div', attr='data-component-name', value='video-player', html=True)},
                ..., {extract_attributes}, all, lambda _, v: v['data-media-id'])):
            media_id = player_data['data-media-id']
            parent_uri = player_data.get('data-video-resource-parent-uri')
            formats, subtitles = [], {}

            video_data = {}
            if parent_uri:
                video_data = self._download_json(
                    'https://fave.api.cnn.io/v1/video', media_id, fatal=False,
                    query={
                        'id': media_id,
                        'stellarUri': parent_uri,
                    })
                for direct_url in traverse_obj(video_data, ('files', ..., 'fileUri', {url_or_none})):