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

Code before:
            'comment_count': int,
            'series': 'Success With Music (SWM)',
        },
    }, {
        'url': 'https://api.spreaker.com/download/episode/12534508/swm_ep15_how_to_market_your_music_part_2.mp3',
        'only_matching': True,
    }, {
        'url': 'https://api.spreaker.com/v2/episodes/12534508?export=episode_segments',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        episode_id, key = self._match_valid_url(url).group(
            'id', 'key')
        query = {}
        if key is not None:
            query = {'key': key}
        data = self._download_json(
            f'https://api.spreaker.com/v2/episodes/{episode_id}',
            episode_id,
            query=query)['response']['episode']
        return _extract_episode(data, episode_id)


class SpreakerPageIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?spreaker\.com/episode/(?P<title>[^/?#]+)-(?P<id>\d+)(?:\?key=(?P<key>[^&]+))?'
    _TESTS = [{
        'url': 'https://www.spreaker.com/episode/ep-15-music-marketing-likes-part-2--12534508',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        episode_id, key = self._match_valid_url(url).group(
            'id', 'key')
        url = f'https://api.spreaker.com/episode/{episode_id}'
        if key is not None:
            url = f'https://api.spreaker.com/episode/{episode_id}?key={key}'
        return self.url_result(
            url,
            ie=SpreakerIE.ie_key(), video_id=episode_id)


class SpreakerShowIE(InfoExtractor):
    _VALID_URL = r'https?://api\.spreaker\.com/show/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://api.spreaker.com/show/4652058',
        'info_dict': {
            'id': '4652058',
        },
        'playlist_mincount': 118,
    }]

Review comment (refactor):
I don't get why we need a separate extractor for the pages. Can't we just match the page URL in `SpreakerIE`?
```py
class SpreakerIE(InfoExtractor):
    _VALID_URL = [
        r'''(?x)
        https?://
            api\.spreaker\.com/
            (?:
                (?:download/)?episode|
                v2/episodes
            )/
            (?P<id>\d+)
        ''',
        r'https?://(?:www\.)?spreaker\.com/episode/[^#?/]*?(?P<id>\d+)/?(?:[?#]|$)',
    ]
```
If you do that, please also add a full test and not just a only_matching one.

Given that the old URLs redirect, I would remove `SpreakerPageIE`.

Code after:
        },
    }, {
        'url': 'https://api.spreaker.com/download/episode/12534508/swm_ep15_how_to_market_your_music_part_2.mp3',
        'only_matching': True,
    }, {
        'url': 'https://api.spreaker.com/v2/episodes/12534508?export=episode_segments',
        'only_matching': True,
    }, {
        'note': 'episode',
        'url': 'https://www.spreaker.com/episode/grunge-music-origins-the-raw-sound-that-defined-a-generation--60269615',
        'info_dict': {
            'id': '60269615',
            'display_id': 'grunge-music-origins-the-raw-sound-that-',
            'ext': 'mp3',
            'title': 'Grunge Music Origins - The Raw Sound that Defined a Generation',
            'description': str,
            'timestamp': 1717468905,
            'upload_date': '20240604',
            'uploader': 'Katie Brown 2',
            'uploader_id': '17733249',
            'duration': 818.83,
            'view_count': int,
            'like_count': int,
            'comment_count': int,
            'series': '90s Grunge',
            'thumbnail': 'https://d3wo5wojvuv7l.cloudfront.net/t_square_limited_160/images.spreaker.com/original/bb0d4178f7cf57cc8786dedbd9c5d969.jpg',
            'creators': ['Katie Brown 2'],
        },
    }, {
        'url': 'https://www.spreaker.com/episode/60269615',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        episode_id = self._match_id(url)
        data = self._download_json(
            f'https://api.spreaker.com/v2/episodes/{episode_id}',
            episode_id, query=traverse_obj(parse_qs(url), {'key': ('key', 0)}))['response']['episode']
        return _extract_episode(data, episode_id)


class SpreakerShowIE(InfoExtractor):
    _VALID_URL = r'https?://api\.spreaker\.com/show/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://api.spreaker.com/show/4652058',
        'info_dict': {
            'id': '4652058',
        },
        'playlist_mincount': 118,
    }]