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

Code before:
        'playlist_count': 17,
    },
    ]

    def getAPIToken(self, videoid: str) -> dict[str, str] | None:
        tokenUrl = 'https://www.agalega.gal/api/fetch-api/jwt/token'

        bodyData = json.dumps({
            'username': None,
            'password': None,
            'client': 'crtvg',
            'checkExistsCookies': False,
        }).encode()

        tokenRaw: dict[str, str] | None = self._download_json(tokenUrl, videoid, data=bodyData)

        if tokenRaw is not None:
            acessToken = str_or_none(tokenRaw.get('access'))
            if acessToken is not None:
                return {'authorization': f'jwtok {acessToken}'}
            else:
                return None
        return None

    def singleVideoExtraction(self, videoid: str, auth_header: dict[str, str]) -> dict[str, str] | None:
        infoUrl = f'https://api-agalega.interactvty.com/api/2.0/contents/content/{videoid}/?optional_fields=image,is_premium,short_description,has_subtitle'
        mediaUrl = f'https://api-agalega.interactvty.com/api/2.0/contents/content_resources/{videoid}/?optional_fields=media_url'
        infoRaw = self._download_json(infoUrl, videoid, headers=auth_header)
        mediaRaw = self._download_json(mediaUrl, videoid, headers=auth_header)

        if (infoRaw is not None and mediaRaw is not None):
            return {
                'id': str(int_or_none(infoRaw.get('id'))),
                'name': str_or_none(infoRaw.get('name')),
                'desc': (str_or_none(infoRaw.get('description') or infoRaw.get('short_description'))),
                'thumbnail': str_or_none(infoRaw.get('image')),
                'masterPlaylist': str_or_none(traverse_obj(mediaRaw, ('results', ..., 'media_url'))[0]),
            }
        return None

    def seriesExtraction(self, seriesid: str, auth_header: dict[str, str]) -> dict[str, str | list[dict[str, str]]] | None:
        categoryUrl = f'https://api-agalega.interactvty.com/api/2.0/contents/category/{seriesid}/?optional_fields=image,short_description,is_premium,description'
        subCategoryUrl = 'https://api-agalega.interactvty.com/api/2.0/contents/subcategory/{category_id}/?optional_fields=image'
        categoryContentsUrl = 'https://api-agalega.interactvty.com/api/2.0/contents/category_contents/{category_id}/?optional_fields=image,short_description'

        categoryRaw: dict[str, str] | None = self._download_json(categoryUrl, seriesid, headers=auth_header)
        if categoryRaw is None:
            return None

        subCategoryRaw = self._download_json(
            subCategoryUrl.format(category_id=seriesid),

Review comment (suggestion):
inline these and put the `optional_fields` inside the `query` arg of `_download_json`

Can add a `_API_BASE` class variable

Code after:
            'title': 'Pulso activo | 18-11-2025',
            'description': 'Anxo, Noemí, Silvia e Estrella  comparten as sensacións da clase de Eddy.',
            'thumbnail': 'https://crtvg-bucket.flumotion.cloud/content_cards/a6bb7da6c8994b82bf961ac6cad1707b.png',
            'ext': 'mp4',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        content_data = self._call_api(
            f'content/{video_id}/', video_id, note='Downloading content data', fatal=False,
            query={
                'optional_fields': 'image,is_premium,short_description,has_subtitle',
            })
        resource_data = self._call_api(
            f'content_resources/{video_id}/', video_id, note='Downloading resource data',
            query={
                'optional_fields': 'media_url',
            })

        formats = []
        subtitles = {}
        for m3u8_url in traverse_obj(resource_data, ('results', ..., 'media_url', {url_or_none})):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                m3u8_url, video_id, ext='mp4', m3u8_id='hls')
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(content_data, {
                'title': ('name', {str}),
                'description': (('description', 'short_description'), {str}, any),
                'thumbnail': ('image', {url_or_none}),
            }),
        }