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

Code before:
        },
        'skip': 'Live might have ended',
    }

    # It's unclear where the chars at the end come from, but they appear to be
    # constant. Might need updating in the future.
    # There are two URLs, some livestreams are in one, and some
    # in the other. The JSON schema is the same for both.
    _API_URLS = ['https://tpfeed.cbc.ca/f/ExhSPC/t_t3UKJR6MAT', 'https://tpfeed.cbc.ca/f/ExhSPC/FNiv9xQx_BnT']

    def _real_extract(self, url):
        video_id = self._match_id(url)

        live_info = self._download_json(self._API_URLS[0], video_id)['entries']
        video_info = None
        for stream in live_info:
            if stream.get('guid') == video_id:
                video_info = stream

        if video_info is None:
            # Try again using other URL
            live_info = self._download_json(self._API_URLS[1], video_id)['entries']
            for stream in live_info:
                if stream.get('guid') == video_id:
                    video_info = stream

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

        return {
            '_type': 'url_transparent',
            'ie_key': 'ThePlatform',
            'url': video_info['content'][0]['url'],
            'id': video_id,
            'title': video_info.get('title'),
            'description': video_info.get('description'),
            'tags': try_get(video_info, lambda x: x['keywords'].split(', ')),
            'thumbnail': video_info.get('cbc$staticImage'),
            'is_live': True,
        }


Review comment (refactor):
Suggestion for L406-L422 (github wont let me comment on unedited lines)
```py
        for api_url in self._API_URLS:
            video_info = next((
                stream for stream in self._download_json(api_url, video_id)['entries']
                if stream.get('guid') == video_id), None)
            if video_info:
                break
        else:
            raise ExtractorError('Couldn\'t find video metadata, maybe this livestream is now offline', expected=True)

```

Code after:
        },
        'skip': 'Live might have ended',
    }

    # It's unclear where the chars at the end come from, but they appear to be
    # constant. Might need updating in the future.
    # There are two URLs, some livestreams are in one, and some
    # in the other. The JSON schema is the same for both.
    _API_URLS = ['https://tpfeed.cbc.ca/f/ExhSPC/t_t3UKJR6MAT', 'https://tpfeed.cbc.ca/f/ExhSPC/FNiv9xQx_BnT']

    def _real_extract(self, url):
        video_id = self._match_id(url)

        for api_url in self._API_URLS:
            video_info = next((
                stream for stream in self._download_json(api_url, video_id)['entries']
                if stream.get('guid') == video_id), None)
            if video_info:
                break
        else:
            raise ExtractorError('Couldn\'t find video metadata, maybe this livestream is now offline', expected=True)

        return {
            '_type': 'url_transparent',
            'ie_key': 'ThePlatform',
            'url': video_info['content'][0]['url'],
            'id': video_id,
            'title': video_info.get('title'),
            'description': video_info.get('description'),
            'tags': try_get(video_info, lambda x: x['keywords'].split(', ')),
            'thumbnail': video_info.get('cbc$staticImage'),
            'is_live': True,
        }