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

Code before:
    def _real_extract(self, url):
        base, post_type, id = self._match_valid_url(url).groups()
        wp = {
            'balkans.aljazeera.net': 'ajb',
            'chinese.aljazeera.net': 'chinese',
            'mubasher.aljazeera.net': 'ajm',
        }.get(base) or 'aje'
        post_type = {
            'features': 'post',
            'program': 'episode',
            'programs': 'episode',
            'videos': 'video',
            'news': 'news',
        }[post_type.split('/')[0]]
        video = self._download_json(
            f'https://{base}/graphql', id, query={
                'wp-site': wp,
                'operationName': 'ArchipelagoSingleArticleQuery',
                'variables': json.dumps({
                    'name': id,
                    'postType': post_type,
                }),
            }, headers={
                'wp-site': wp,
            })
        video = try_get(video, lambda x: x['data']['article']['video'])
        video_id = video.get('id')
        account = video.get('accountId') or '911432371001'
        player_id = video.get('playerId') or 'csvTfAlKW'
        embed = 'default'

        if video_id is None:
            webpage = self._download_webpage(url, id)

            account, player_id, embed, video_id = self._search_regex(self.BRIGHTCOVE_URL_RE, webpage, 'video id',
                                                                     group=(1, 2, 3, 4), default=(None, None, None, None))

            if video_id is None:
                return {
                    '_type': 'url_transparent',
                    'url': url,
                    'ie_key': 'Generic'
                }

        return {
            '_type': 'url_transparent',
            'url': f'https://players.brightcove.net/{account}/{player_id}_{embed}/index.html?videoId={video_id}',
            'ie_key': 'BrightcoveNew'
        }


Review comment (bug):
```suggestion
        video = try_get(video, lambda x: x['data']['article']['video']) or {}
```
otherwise the below .get may fail

Code after:
    def _real_extract(self, url):
        base, post_type, id = self._match_valid_url(url).groups()
        wp = {
            'balkans.aljazeera.net': 'ajb',
            'chinese.aljazeera.net': 'chinese',
            'mubasher.aljazeera.net': 'ajm',
        }.get(base) or 'aje'
        post_type = {
            'features': 'post',
            'program': 'episode',
            'programs': 'episode',
            'videos': 'video',
            'news': 'news',
        }[post_type.split('/')[0]]
        video = self._download_json(
            f'https://{base}/graphql', id, query={
                'wp-site': wp,
                'operationName': 'ArchipelagoSingleArticleQuery',
                'variables': json.dumps({
                    'name': id,
                    'postType': post_type,
                }),
            }, headers={
                'wp-site': wp,
            })
        video = try_get(video, lambda x: x['data']['article']['video']) or {}
        video_id = video.get('id')
        account = video.get('accountId') or '911432371001'
        player_id = video.get('playerId') or 'csvTfAlKW'
        embed = 'default'

        if video_id is None:
            webpage = self._download_webpage(url, id)

            account, player_id, embed, video_id = self._search_regex(self.BRIGHTCOVE_URL_RE, webpage, 'video id',
                                                                     group=(1, 2, 3, 4), default=(None, None, None, None))

            if video_id is None:
                return {
                    '_type': 'url_transparent',
                    'url': url,
                    'ie_key': 'Generic'
                }

        return {
            '_type': 'url_transparent',
            'url': f'https://players.brightcove.net/{account}/{player_id}_{embed}/index.html?videoId={video_id}',
            'ie_key': 'BrightcoveNew'
        }