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

Code before:
            'thumbnail': video.get('imageUrl') or video.get('thumbnailUrl'),
            'duration': int_or_none(video.get('duration')),
            'description': video.get('description'),
            'ie_key': 'Youtube',
        }

    def _real_extract(self, url):
        display_id = self._match_id(url)
        component_props = self._parse_json(
            self._download_json(
                'https://www.khanacademy.org/api/internal/graphql/FetchContentData',
                display_id,
                query={
                    'fastly_cacheable': ['persist_until_publish'],
                    'hash': ['4134764944'],
                    'lang': ['en'],
                    'variables': [
                        '{"path":"'
                        + display_id
                        + '","queryParams":"lang=en","isModal":false,"followRedirects":true,"countryCode":"US"}'
                    ],
                },
            )['data']['contentJson'],
            display_id,
        )['componentProps']
        return self._parse_component_props(component_props)


class KhanAcademyIE(KhanAcademyBaseIE):
    IE_NAME = 'khanacademy'
    _VALID_URL = KhanAcademyBaseIE._VALID_URL_TEMPL % ('4', 'v/')
    _TEST = {
        'url': 'https://www.khanacademy.org/computing/computer-science/cryptography/crypt/v/one-time-pad',
        'md5': '9c84b7b06f9ebb80d22a5c8dedefb9a0',
        'info_dict': {
            'id': 'FlIG3TvQCBQ',
            'ext': 'mp4',
            'title': 'The one-time pad',
            'description': 'The perfect cipher',
            'duration': 176,
            'uploader': 'Brit Cruise',
            'uploader_id': 'khanacademy',
            'upload_date': '20120411',
            'timestamp': 1334170113,
            'license': 'cc-by-nc-sa',
        },
        'add_ie': ['Youtube'],
    }

    def _parse_component_props(self, component_props):
        video = component_props['tutorialPageData']['contentModel']

Review comment (suggestion):
```py
        content = self._download_json(
            ...)['data']['contentJson']
        return self._parse_component_props(self._parse_json(content, display_id)['componentProps'])
```

Code after:
            'id': video.get('slug'),
            'title': video.get('title'),
            'thumbnail': video.get('imageUrl') or video.get('thumbnailUrl'),
            'duration': int_or_none(video.get('duration')),
            'description': video.get('description'),
            'ie_key': 'Youtube',
        }

    def _real_extract(self, url):
        display_id = self._match_id(url)
        content = self._download_json(
            'https://www.khanacademy.org/api/internal/graphql/FetchContentData',
            display_id, query={
                'fastly_cacheable': 'persist_until_publish',
                'hash': '4134764944',
                'lang': 'en',
                'variables': json.dumps({
                    'path': display_id,
                    'queryParams': 'lang=en',
                    'isModal': False,
                    'followRedirects': True,
                    'countryCode': 'US',
                }),
            })['data']['contentJson']
        return self._parse_component_props(self._parse_json(content, display_id)['componentProps'])


class KhanAcademyIE(KhanAcademyBaseIE):
    IE_NAME = 'khanacademy'
    _VALID_URL = KhanAcademyBaseIE._VALID_URL_TEMPL % ('4', 'v/')
    _TEST = {
        'url': 'https://www.khanacademy.org/computing/computer-science/cryptography/crypt/v/one-time-pad',
        'md5': '9c84b7b06f9ebb80d22a5c8dedefb9a0',
        'info_dict': {
            'id': 'FlIG3TvQCBQ',
            'ext': 'mp4',
            'title': 'The one-time pad',
            'description': 'The perfect cipher',
            'duration': 176,
            'uploader': 'Brit Cruise',
            'uploader_id': 'khanacademy',
            'upload_date': '20120411',
            'timestamp': 1334170113,
            'license': 'cc-by-nc-sa',
        },
        'add_ie': ['Youtube'],
    }

    def _parse_component_props(self, component_props):
        video = component_props['tutorialPageData']['contentModel']
        info = self._parse_video(video)