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

Code before:
            'description': 'O cómico ademais fai un repaso dalgúns momentos da súa traxectoria profesional',
            'thumbnail': 'https://crtvg-bucket.flumotion.cloud/content_cards/2ef32c3b9f6249d9868fd8f11d389d3d.png',
            'ext': 'mp4',
        },
    },
        {
        'url': 'https://www.agalega.gal/videos/detail/296152-pulso-activo-7',
        'md5': '26df7fdcf859f38ad92d837279d6b56d',
        'info_dict': {
            'id': '296152',
            '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)
        info_url = f'https://api-agalega.interactvty.com/api/2.0/contents/content/{video_id}/?optional_fields=image,is_premium,short_description,has_subtitle'
        media_url = f'https://api-agalega.interactvty.com/api/2.0/contents/content_resources/{video_id}/?optional_fields=media_url'
        auth_header = self._get_access_token(video_id)

        if auth_header is not None:
            info_raw = self._download_json(info_url, video_id, headers=auth_header)
            media_raw = self._download_json(media_url, video_id, headers=auth_header)

            if info_raw is not None and media_raw is not None:
                m3u8_url = traverse_obj(media_raw, ('results', ..., 'media_url', {url_or_none}, any, {require('media_url')}))
                formats = self._extract_m3u8_formats_and_subtitles(
                    m3u8_url, video_id, ext='mp4',
                    m3u8_id='hls', entry_protocol='m3u8_native', fatal=False,
                )
                return {
                    'id': traverse_obj(info_raw, ('id', {int}, {str_or_none}, {require('id')})),
                    'formats': formats[0],
                    **traverse_obj(info_raw, {
                        'title': ('name', {str_or_none}),
                        'description': (('description', 'short_description'), {str_or_none}, any),
                        'thumbnail': ('image', {url_or_none}),
                    }),
                }
            else:
                return None
        return None


class AGalegaSeriesIE(AGalegaBaseIE):
    IE_NAME = 'agalega:series'
    _VALID_URL = r'https?://(?:www\.)?agalega\.gal/videos/category/(?P<id>[0-9]+)'
    _TESTS = [{

Review comment (security):
The URLs should be inlined and query parameters passed as a dict.
```suggestion
        auth_headers = self._get_access_token(video_id)

        content_data = self._download_json(
            f'https://api-agalega.interactvty.com/api/2.0/contents/content/{video_id}/', video_id,
            note='Downloading content data', fatal=False, headers=auth_headers,
            query={
                'optional_fields': 'image,is_premium,short_description,has_subtitle',
            })
        resource_data = self._download_json(
            f'https://api-agalega.interactvty.com/api/2.0/contents/content_resources/{video_id}/',
            video_id, note='Downloading resource data', headers=auth_headers,
            query={
                'optional_fields': 'media_url',
            })
```
If there is nothing useful to be done without data, we can have it be fatal. The extractor would error out either way.

Code after:
            'thumbnail': 'https://crtvg-bucket.flumotion.cloud/content_cards/2ef32c3b9f6249d9868fd8f11d389d3d.png',
            'ext': 'mp4',
        },
    }, {
        'url': 'https://www.agalega.gal/videos/detail/296152-pulso-activo-7',
        'md5': '26df7fdcf859f38ad92d837279d6b56d',
        'info_dict': {
            'id': '296152',
            '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}),
            }),
        }