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

Code before:
        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 = [{
        'url': 'https://www.agalega.gal/videos/category/27035-galician-friki',
        'info_dict': {
            'id': '27035',
            'title': 'Galician Friki',
            'description': 'md5:68279845eea70ba3b4324bd96e3aac30',
            'thumbnail': 'https://crtvg-bucket.flumotion.cloud/category_cards/f1d4e23fa336467ba9b1330f6224c589.jpg',
        },
        'playlist_count': 7,
    },
        {
        'url': 'https://www.agalega.gal/videos/category/17175-na-gloria?cat=17176',
        'info_dict': {
            'id': '17175',
            'title': 'Na Gloria',
            'description': 'Na parroquia da Gloria vivíase ben... ata que chegaron unha madrileña e un andaluz e abriron un hotel "refinado".\n',
            'thumbnail': 'https://crtvg-bucket.flumotion.cloud/category_cards/a54fd2bcfbde439f88bb0f537335fc2a.png',
        },
        'playlist_count': 17,
    },

Review comment (suggestion):
Any reason not to use the video_id from the URL?
```suggestion
        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(content_data, {
                'title': ('name', {str}),
                'description': (('description', 'short_description'), {str_or_none}, any),
                'thumbnail': ('image', {url_or_none}),
            }),
        }
```

Code after:
            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}),
            }),
        }