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

Code before:
            'subtitles': subtitles,
        }


class BrainPOPLegacyBaseIE(BrainPOPBaseIE):
    def _parse_js_topic_data(self, topic_data, display_id, token):
        movie_data = topic_data['movies']
        # TODO: Are there non-burned subtitles?
        formats = self._extract_adaptive_formats(movie_data, token, display_id)

        return {
            'id': topic_data['EntryID'],
            'display_id': display_id,
            'title': topic_data.get('name'),
            'alt_title': topic_data.get('title'),
            'description': topic_data.get('synopsis'),
            'formats': formats,
        }

    def _real_extract(self, url):
        slug, display_id = self._match_valid_url(url).group('slug', 'id')
        webpage = self._download_webpage(url, display_id)
        topic_data = self._parse_json(
            self._search_regex(r'var\s+content\s*=\s*({.+?});', webpage, 'content data'),
            display_id)['category']['unit']['topic']
        token = self._search_regex(r'ec_token\s*:\s*[\'"](.+)[\'"]', webpage, 'video token')
        return self._parse_js_topic_data(topic_data, display_id, token)


class BrainPOPJrIE(BrainPOPLegacyBaseIE):
    _VALID_URL = r'https?://jr\.brainpop\.com\/(?P<slug>[^/]+/[^/]+/(?P<id>[^/?#&]+))'
    _VIDEO_URL = 'https://svideos-jr.brainpop.com'
    _HLS_URL = 'https://hls-jr.brainpop.com'
    _CDN_URL = 'https://cdn-jr.brainpop.com'
    _ORIGIN = 'https://jr.brainpop.com'
    _TESTS = [{
        'url': 'https://jr.brainpop.com/health/feelingsandsel/emotions/',
        'md5': '04e0561bb21770f305a0ce6cf0d869ab',
        'info_dict': {
            'id': '347',
            'ext': 'mp4',
            'title': 'Emotions',
            'display_id': 'emotions',
        },
    }, {
        'url': 'https://jr.brainpop.com/science/habitats/arctichabitats/',
        'md5': 'b0ed063bbd1910df00220ee29340f5d6',
        'info_dict': {
            'id': '29',
            'ext': 'mp4',
            'title': 'Arctic Habitats',

Review comment (suggestion):
```suggestion
        token = self._search_regex(r'ec_token\s*:\s*[\'"]([^\'"]+)', webpage, 'video token')
```

Code after:
            'formats': formats,
            'subtitles': subtitles,
        }


class BrainPOPLegacyBaseIE(BrainPOPBaseIE):
    def _parse_js_topic_data(self, topic_data, display_id, token):
        movie_data = topic_data['movies']
        # TODO: Are there non-burned subtitles?
        formats = self._extract_adaptive_formats(movie_data, token, display_id)

        return {
            'id': topic_data['EntryID'],
            'display_id': display_id,
            'title': topic_data.get('name'),
            'alt_title': topic_data.get('title'),
            'description': topic_data.get('synopsis'),
            'formats': formats,
        }

    def _real_extract(self, url):
        slug, display_id = self._match_valid_url(url).group('slug', 'id')
        webpage = self._download_webpage(url, display_id)
        topic_data = self._search_json(
            r'var\s+content\s*=\s*', webpage, 'content data',
            display_id, end_pattern=';')['category']['unit']['topic']
        token = self._search_regex(r'ec_token\s*:\s*[\'"]([^\'"]+)', webpage, 'video token')
        return self._parse_js_topic_data(topic_data, display_id, token)


class BrainPOPJrIE(BrainPOPLegacyBaseIE):
    _ORIGIN = 'https://jr.brainpop.com'
    _VIDEO_URL = 'https://svideos-jr.brainpop.com'
    _HLS_URL = 'https://hls-jr.brainpop.com'
    _CDN_URL = 'https://cdn-jr.brainpop.com'
    _TESTS = [{
        'url': 'https://jr.brainpop.com/health/feelingsandsel/emotions/',
        'md5': '04e0561bb21770f305a0ce6cf0d869ab',
        'info_dict': {
            'id': '347',
            'ext': 'mp4',
            'title': 'Emotions',
            'display_id': 'emotions',
        },
    }, {
        'url': 'https://jr.brainpop.com/science/habitats/arctichabitats/',
        'md5': 'b0ed063bbd1910df00220ee29340f5d6',
        'info_dict': {
            'id': '29',
            'ext': 'mp4',
            'title': 'Arctic Habitats',