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

Code before:
                'description': 'md5:7fe8e3d5806f96002e55f190d1d94479',
                'uploader': 'The Voice',
                'uploader_id': 'NBCTheVoice',
                'upload_date': '20191029',
            },
        }],
        'params': {
            'playlistend': 2,
        },
        'expected_warnings': ['HTTP Error 404', 'Ignoring subtitle tracks'],
    }, {
        'url': 'https://malaysia.news.yahoo.com/video/bystanders-help-ontario-policeman-bust-190932818.html',
        'only_matching': True,
    }, {
        'url': 'https://es-us.noticias.yahoo.com/es-la-puerta-irrompible-que-110539379.html',
        'only_matching': True,
    }, {
        'url': 'https://www.yahoo.com/entertainment/v/longtime-cbs-news-60-minutes-032036500-cbs.html',
        'only_matching': True,
    }]

    def _extract_yahoo_video(self, video_id, country):
        data = self._download_json(
            f'https://video-api.yql.yahoo.com/v1/video/sapi/streams/{video_id}',
            video_id, 'Downloading video JSON metadata')
        video = traverse_obj(data, ('query', 'results', 'mediaObj', 0, 'meta'))
        if country == 'malaysia':
            country = 'my'

        is_live = video.get('uplynk_live')
        fmts = ('m3u8',) if is_live else ('webm', 'mp4')

        urls = []
        formats = []
        subtitles = {}
        for fmt in fmts:
            media_obj = self._download_json(
                'https://video-api.yql.yahoo.com/v1/video/sapi/streams/' + video_id,
                video_id, f'Downloading {fmt} JSON metadata',
                headers=self.geo_verification_headers(), query={
                    'format': fmt,
                    'region': country.upper(),
                })['query']['results']['mediaObj'][0]
            msg = media_obj.get('status', {}).get('msg')

            for s in media_obj.get('streams', []):
                host = s.get('host')
                path = s.get('path')
                if not host or not path:
                    continue
                s_url = host + path

Review comment (suggestion):
Let's get rid of the intermediate `data` var that we don't use anywhere else, and this can be fatal since we don't have anything without it
```suggestion
        video = self._download_json(
            f'https://video-api.yql.yahoo.com/v1/video/sapi/streams/{video_id}',
            video_id, 'Downloading video JSON metadata')['query']['results']['mediaObj'][0]['meta']
```

Code after:
                headers=self.geo_verification_headers(), query={
                    'format': fmt,
                    'region': country.upper(),
                })['query']['results']['mediaObj'][0]
            msg = media_obj.get('status', {}).get('msg')

            for s in media_obj.get('streams', []):
                host = s.get('host')
                path = s.get('path')
                if not host or not path:
                    continue
                s_url = host + path
                if s.get('format') == 'm3u8':
                    formats.extend(self._extract_m3u8_formats(
                        s_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
                    continue
                tbr = int_or_none(s.get('bitrate'))
                formats.append({
                    'url': s_url,
                    'format_id': join_nonempty(fmt, tbr),
                    'width': int_or_none(s.get('width')),
                    'height': int_or_none(s.get('height')),
                    'tbr': tbr,
                    'fps': int_or_none(s.get('framerate')),
                })

            for cc in media_obj.get('closedcaptions', []):
                cc_url = cc.get('url')
                if not cc_url or cc_url in urls:
                    continue
                urls.append(cc_url)
                subtitles.setdefault(cc.get('lang') or 'en-US', []).append({
                    'url': cc_url,
                    'ext': mimetype2ext(cc.get('content_type')),
                })

        if not formats and msg == 'geo restricted':
            self.raise_geo_restricted(metadata_available=True)

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            'is_live': is_live,
            **traverse_obj(video, {
                'title': ('title', {clean_html}),
                'description': ('description', {clean_html}),
                'thumbnail': ('thumbnail', {url_or_none}, {update_url(scheme='https')}),
                'timestamp': ('publish_time', {parse_iso8601}),
                'duration': ('duration', {int_or_none}),
                'view_count': ('view_count', {int_or_none}),