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

Code before:
            'series': 'Analizy',
        },
    }]

    def _real_extract(self, url):
        media_id = self._match_id(url)

        # in case it breaks see this but it returns a lot of useless data
        # https://api.podcast.radioagora.pl/api4/getPodcasts?podcast_id=100091&with_guests=true&with_leaders_for_mobile=true
        metadata = self._download_json(
            f'https://audycje.tokfm.pl/getp/3{media_id}', media_id, 'Downloading podcast metadata')
        if not metadata:
            raise ExtractorError('No such podcast', expected=True)
        metadata = metadata[0]

        formats = []
        url_data = self._download_json(
            f'https://api.podcast.radioagora.pl/api4/getSongUrl?podcast_id={media_id}&device_id={uuid.uuid4()}&ppre=false&audio=mp3',
            media_id, 'Downloading podcast mp3 URL')
        if 'link_ssl' in url_data:
            formats.append({
                'url': url_data['link_ssl'],
                'ext': 'mp3',
                'vcodec': 'none',
                'acodec': 'mp3',
            })

        return {
            'id': media_id,
            'formats': formats,
            'title': metadata.get('podcast_name'),
            'series': metadata.get('series_name'),
            'episode': metadata.get('podcast_name'),
        }


class TokFMAuditionIE(InfoExtractor):
    _VALID_URL = r'(?:https?://audycje\.tokfm\.pl/audycja/|tokfm:audition:)(?P<id>\d+),?'
    IE_NAME = 'tokfm:audition'
    _TESTS = [{
        'url': 'https://audycje.tokfm.pl/audycja/218,Analizy',
        'info_dict': {
            'id': '218',
            'title': 'Analizy',
            'series': 'Analizy',
        },
        'playlist_count': 1635,
    }]

    _PAGE_SIZE = 30
    _HEADERS = {

Review comment (refactor):
I would even further simplify this. Remove the `formats` var init above, inline the `url`/`ext`/codec fields in the return (`acodec` is redundant now, core code will set it from `ext`)

```suggestion
        mp3_url = self._download_json(
            'https://api.podcast.radioagora.pl/api4/getSongUrl',
            media_id, 'Downloading podcast mp3 URL', query={
                'podcast_id': media_id,
                'device_id': str(uuid.uuid4()),
                'ppre': 'false',
                'audio': 'mp3',
            })['link_ssl']
```
```diff
         return {
             'id': media_id,
-            'formats': formats,
+            'url': mp3_url,
+            'vcodec': 'none',
+            'ext': 'mp3',
```

Code after:
            'series': 'Analizy',
        },
    }]

    def _real_extract(self, url):
        media_id = self._match_id(url)

        # in case it breaks see this but it returns a lot of useless data
        # https://api.podcast.radioagora.pl/api4/getPodcasts?podcast_id=100091&with_guests=true&with_leaders_for_mobile=true
        metadata = self._download_json(
            f'https://audycje.tokfm.pl/getp/3{media_id}', media_id, 'Downloading podcast metadata')
        if not metadata:
            raise ExtractorError('No such podcast', expected=True)
        metadata = metadata[0]

        mp3_url = self._download_json(
            'https://api.podcast.radioagora.pl/api4/getSongUrl',
            media_id, 'Downloading podcast mp3 URL', query={
                'podcast_id': media_id,
                'device_id': str(uuid.uuid4()),
                'ppre': 'false',
                'audio': 'mp3',
            })['link_ssl']

        return {
            'id': media_id,
            'url': mp3_url,
            'vcodec': 'none',
            'ext': 'mp3',
            'title': metadata.get('podcast_name'),
            'series': metadata.get('series_name'),
            'episode': metadata.get('podcast_name'),
        }


class TokFMAuditionIE(InfoExtractor):
    _VALID_URL = r'(?:https?://audycje\.tokfm\.pl/audycja/|tokfm:audition:)(?P<id>\d+),?'
    IE_NAME = 'tokfm:audition'
    _TESTS = [{
        'url': 'https://audycje.tokfm.pl/audycja/218,Analizy',
        'info_dict': {
            'id': '218',
            'title': 'Analizy',
            'series': 'Analizy',
        },
        'playlist_count': 1635,
    }]

    _PAGE_SIZE = 30
    _HEADERS = {
        'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Redmi 3S Build/PQ3A.190801.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.101 Mobile Safari/537.36',