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

Code before:
    parse_iso8601,
    traverse_obj,
)


class TuneInBaseIE(InfoExtractor):
    _VALID_URL_BASE = r'https?://(?:www\.)?tunein\.com'

    def _extract_metadata(self, webpage, content_id):
        return self._search_json(r'window.INITIAL_STATE=', webpage, 'hydration', content_id, fatal=False)

    def _extract_formats_and_subtitles(self, content_id):
        streams = self._download_json(
            f'https://opml.radiotime.com/Tune.ashx?render=json&formats=mp3,aac,ogg,flash,hls&id={content_id}',
            content_id)['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)
            elif determine_ext(stream['url']) == 'pls':
                playlist_content = self._download_webpage(stream['url'], content_id)
                formats.append({
                    'url': self._search_regex(r'File1=(.*)', playlist_content, 'url', fatal=False),
                    'abr': stream.get('bitrate'),
                    'ext': stream.get('media_type'),
                })
            else:
                formats.append({
                    'url': stream['url'],
                    'abr': stream.get('bitrate'),
                    'ext': stream.get('media_type'),
                })

        return formats, subtitles


class TuneInStationIE(TuneInBaseIE):
    _VALID_URL = TuneInBaseIE._VALID_URL_BASE + r'(?:/radio/[^?&]+-|/embed/player/)(?P<id>s\d+)'
    _EMBED_REGEX = [r'<iframe[^>]+src=["\'](?P<url>(?:https?://)?tunein\.com/embed/player/s\d+)']

    _TESTS = [{
        'url': 'https://tunein.com/radio/Jazz24-885-s34682/',
        'info_dict': {
            'id': 's34682',
            'title': 're:^Jazz24',
            'description': 'md5:d6d0b89063fd68d529fa7058ee98619b',
            'thumbnail': 're:^https?://[^?&]+/s34682',
            'location': 'Seattle-Tacoma, US',

Review comment (suggestion):
```suggestion
                    'url': self._search_regex(r'File1=(.*)', playlist_content, 'url'),
```

Code after:
    parse_iso8601,
    traverse_obj,
)


class TuneInBaseIE(InfoExtractor):
    _VALID_URL_BASE = r'https?://(?:www\.)?tunein\.com'

    def _extract_metadata(self, webpage, content_id):
        return self._search_json(r'window.INITIAL_STATE=', webpage, 'hydration', content_id, fatal=False)

    def _extract_formats_and_subtitles(self, content_id):
        streams = self._download_json(
            f'https://opml.radiotime.com/Tune.ashx?render=json&formats=mp3,aac,ogg,flash,hls&id={content_id}',
            content_id)['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)
            elif determine_ext(stream['url']) == 'pls':
                playlist_content = self._download_webpage(stream['url'], content_id)
                formats.append({
                    'url': self._search_regex(r'File1=(.*)', playlist_content, 'url', fatal=False),
                    'abr': stream.get('bitrate'),
                    'ext': stream.get('media_type'),
                })
            else:
                formats.append({
                    'url': stream['url'],
                    'abr': stream.get('bitrate'),
                    'ext': stream.get('media_type'),
                })

        return formats, subtitles


class TuneInStationIE(TuneInBaseIE):
    _VALID_URL = TuneInBaseIE._VALID_URL_BASE + r'(?:/radio/[^?#]+-|/embed/player/)(?P<id>s\d+)'
    _EMBED_REGEX = [r'<iframe[^>]+src=["\'](?P<url>(?:https?://)?tunein\.com/embed/player/s\d+)']

    _TESTS = [{
        'url': 'https://tunein.com/radio/Jazz24-885-s34682/',
        'info_dict': {
            'id': 's34682',
            'title': 're:^Jazz24',
            'description': 'md5:d6d0b89063fd68d529fa7058ee98619b',
            'thumbnail': 're:^https?://[^?&]+/s34682',
            'location': 'Seattle-Tacoma, US',