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

Code before:
        path = f'/{endpoint}' if endpoint else ''

        return self._download_json(
            f'https://api.tunein.com/profiles/{item_id}{path}', item_id, note=note, query=query)

    def _extract_formats_and_subtitles(self, content_id):
        streams = self._download_json(
            'https://opml.radiotime.com/Tune.ashx', content_id, query={
                'formats': 'mp3,aac,ogg,flash,hls',
                'id': content_id,
                'render': 'json',
            },
        )['body']

        formats, subtitles = [], {}
        for stream in streams:
            if stream.get('media_type') == 'hls':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(stream['url'], content_id, fatal=False)
                formats.extend(fmts)
                self._merge_subtitles(subs, target=subtitles)
            else:
                formats.append(traverse_obj(stream, {
                    'abr': ('bitrate', {int_or_none}),
                    'ext': ('media_type', {str}),
                    'url': ('url', {self._proto_relative_url}, {url_or_none}),
                }))

        return formats, subtitles


class TuneInStationIE(TuneInBaseIE):
    IE_NAME = 'tunein:station'
    _VALID_URL = r'https?://tunein\.com/radio/[^/]+(?P<id>s\d+)'
    _TESTS = [{
        'url': 'https://tunein.com/radio/Jazz24-885-s34682/',
        'info_dict': {
            'id': 's34682',
            'ext': 'mp3',
            'title': str,
            'alt_title': 'World Class Jazz',
            'channel_follower_count': int,
            'description': 'md5:d6d0b89063fd68d529fa7058ee98619b',
            'location': 'Seattle-Tacoma, US',
            'live_status': 'is_live',
            'thumbnail': r're:https?://.+',
        },
        'params': {'skip_download': 'Livestream'},
    }, {
        'url': 'https://tunein.com/radio/BBC-Radio-1-988-s24939/',
        'info_dict': {
            'id': 's24939',

Review comment (suggestion):
```suggestion
                formats.append(traverse_obj(stream, {
                    'abr': ('bitrate', {int_or_none}),
                    'ext': ('media_type', {str}),
                    'url': ('url', {self._proto_relative_url}),
                }))
```

Code after:

class TuneInBaseIE(InfoExtractor):
    def _call_api(self, item_id, endpoint=None, note='Downloading JSON metadata', fatal=False, query=None):
        return self._download_json(
            join_nonempty('https://api.tunein.com/profiles', item_id, endpoint, delim='/'),
            item_id, note=note, fatal=fatal, query=query) or {}

    def _extract_formats_and_subtitles(self, content_id):
        streams = self._download_json(
            'https://opml.radiotime.com/Tune.ashx', content_id, query={
                'formats': 'mp3,aac,ogg,flash,hls',
                'id': content_id,
                'render': 'json',
            })

        formats, subtitles = [], {}
        for stream in traverse_obj(streams, ('body', lambda _, v: url_or_none(v['url']))):
            if stream.get('media_type') == 'hls':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(stream['url'], content_id, fatal=False)
                formats.extend(fmts)
                self._merge_subtitles(subs, target=subtitles)
            else:
                formats.append(traverse_obj(stream, {
                    'abr': ('bitrate', {int_or_none}),
                    'ext': ('media_type', {str}),
                    'url': ('url', {self._proto_relative_url}),
                }))

        return formats, subtitles


class TuneInStationIE(TuneInBaseIE):
    IE_NAME = 'tunein:station'
    _VALID_URL = r'https?://tunein\.com/radio/[^/?#]+(?P<id>s\d+)'
    _TESTS = [{
        'url': 'https://tunein.com/radio/Jazz24-885-s34682/',
        'info_dict': {
            'id': 's34682',
            'ext': 'mp3',
            'title': str,
            'alt_title': 'World Class Jazz',
            'channel_follower_count': int,
            'description': 'md5:d6d0b89063fd68d529fa7058ee98619b',
            'location': r're:Seattle-Tacoma, (?:US|WA)',
            'live_status': 'is_live',
            'thumbnail': r're:https?://.+',
        },
        'params': {'skip_download': 'Livestream'},
    }, {
        'url': 'https://tunein.com/radio/BBC-Radio-1-988-s24939/',
        'info_dict': {