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

Code before:
                        'title': episode['title'],
                        'url': episode['file'],
                        'duration': int_or_none(episode.get('duration')),
                        'timestamp': parse_iso8601(episode.get('datePublic')),
                    }
                not_empty = len(page['data']) > 0
                i += 1

        if has_articles:
            not_empty = True
            i = 0
            while not_empty:
                page = self._call_lp3(
                    'Article/GetListByCategoryId', {
                        'categoryId': playlist_id,
                        'PageSize': 9,
                        'skip': i,
                        'format': 400,
                    }, playlist_id, f'Downloading article list (page #{i})')
                for article in page['data']:
                    yield {
                        '_type': 'url_transparent',
                        'id': str(article['id']),
                        'title': article['shortTitle'],
                        'url': article['url'],
                        'ie_key': PolskieRadioIE,
                        'description': traverse_obj(article, ('description', 'lead')),
                        'timestamp': parse_iso8601(article.get('datePublic')),
                    }
                not_empty = len(page['data']) > 0
                i += 1

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

        page_props = traverse_obj(
            self._search_nextjs_data(self._download_webpage(url, playlist_id), playlist_id),
            ('props', 'pageProps', ('data', None)))
        details = page_props.get('details', {})

        has_episodes = len(page_props.get('episodes', ())) > 0 or len(page_props.get('audios', ())) > 0
        has_articles = len(page_props.get('articles', ())) > 0

        return self.playlist_result(
            self._entries(playlist_id, has_episodes, has_articles), playlist_id,
            details.get('name'), traverse_obj(details, ('description', 'lead')),
            thumbnail=details.get('photo'))


class PolskieRadioCategoryIE(InfoExtractor):
    # legacy sites

Review comment (refactor):
hm, this doesn't seem to work? works with `.ie_key()`
```
ERROR: No suitable extractor (<class 'yt_dlp.extractor.polskieradio.PolskieRadioIE'>) found for URL https://jedynka.polskieradio.pl/artykul/1587425,Historia-zywa-nowy-cykl-w-radiowej-Jedynce
```

Code after:
                    'title': episode.get('title'),
                    'duration': int_or_none(episode.get('duration')),
                    'timestamp': parse_iso8601(episode.get('datePublic')),
                }

        for i in itertools.count(1) if has_articles else []:
            page = self._call_lp3(
                'Article/GetListByCategoryId', {
                    'categoryId': playlist_id,
                    'PageSize': 9,
                    'skip': i,
                    'format': 400,
                }, playlist_id, f'Downloading article list page {i}')
            if not traverse_obj(page, 'data'):
                break
            for article in page['data']:
                yield {
                    '_type': 'url_transparent',
                    'ie_key': PolskieRadioIE.ie_key(),
                    'id': str(article['id']),
                    'url': article['url'],
                    'title': article.get('shortTitle'),
                    'description': traverse_obj(article, ('description', 'lead')),
                    'timestamp': parse_iso8601(article.get('datePublic')),
                }

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

        page_props = traverse_obj(
            self._search_nextjs_data(self._download_webpage(url, playlist_id), playlist_id),
            ('props', 'pageProps', ('data', None)), get_all=False)

        has_episodes = bool(traverse_obj(page_props, 'episodes', 'audios'))
        has_articles = bool(traverse_obj(page_props, 'articles'))

        return self.playlist_result(
            self._entries(playlist_id, has_episodes, has_articles), playlist_id,
            title=traverse_obj(page_props, ('details', 'name')),
            description=traverse_obj(page_props, ('details', 'description', 'lead')),
            thumbnail=traverse_obj(page_props, ('details', 'photo')))


class PolskieRadioCategoryIE(InfoExtractor):
    # legacy sites
    IE_NAME = 'polskieradio:category'
    _VALID_URL = r'https?://(?:www\.)?polskieradio\.pl/\d+(?:,[^/]+)?/(?P<id>\d+)'
    _TESTS = [{
        'url': 'http://www.polskieradio.pl/7/129,Sygnaly-dnia?ref=source',
        'only_matching': True
    }, {