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

Code before:
                    f'https://www.rtve.es/api/programas/{program_id}/videos?{urllib.parse.urlencode(params)}',
                    program_slug,
                )
                current_page += 1
                total_page_count = traverse_obj(videos_data, ('page', 'totalPages'), default=1)
                entries.extend(
                    {
                        '_type': 'url_transparent',
                        **traverse_obj(video, {
                            'url': ('htmlUrl', {url_or_none}),
                            'id': ('id', {str.strip}),
                            'title': ('longTitle', {str.strip}),
                            'description': ('shortDescription', {str.strip}),
                            'duration': ('duration', {float_or_none(scale=1000)}),
                            'series': (('programInfo', 'title'), {str.strip}),
                            'season_number': ('temporadaOrden', {int}),
                            'season_id': ('temporadaId', {str.strip}),
                            'season': ('temporada', {str.strip}),
                            'episode_number': ('episode', {int}),
                            'episode': ('title', {str.strip}),
                            'thumbnail': ('thumbnail', {url_or_none}),
                        }),
                    } for video in traverse_obj(videos_data, ('page', 'items'))
                )

        return self.playlist_result(entries, program_slug, playlist_title)


Review comment (refactor):
```suggestion
        program_slug = self._match_id(url)
        program_page = self._download_webpage(url, program_slug)

        program_id = self._html_search_meta('DC.identifier', program_page, 'Program ID', fatal=False)

        return self.playlist_result(
            self._entries(program_id), program_id, self._html_extract_title(program_page))
```

Code after:
            })

    def _entries(self, page_data):
        for video in traverse_obj(page_data, ('page', 'items', lambda _, v: url_or_none(v['htmlUrl']))):
            yield self.url_result(
                video['htmlUrl'], RTVEALaCartaIE, url_transparent=True,
                **traverse_obj(video, {
                    'id': ('id', {str}),
                    'title': ('longTitle', {str}),
                    'description': ('shortDescription', {str}),
                    'duration': ('duration', {float_or_none(scale=1000)}),
                    'series': (('programInfo', 'title'), {str}, any),
                    'season_number': ('temporadaOrden', {int_or_none}),
                    'season_id': ('temporadaId', {str}),
                    'season': ('temporada', {str}),
                    'episode_number': ('episode', {int_or_none}),
                    'episode': ('title', {str}),
                    'thumbnail': ('thumbnail', {url_or_none}),
                }),
            )

    def _real_extract(self, url):
        program_slug = self._match_id(url)
        program_page = self._download_webpage(url, program_slug)

        program_id = self._html_search_meta('DC.identifier', program_page, 'Program ID', fatal=True)

        first_page = self._fetch_page(program_id, 1)
        page_count = traverse_obj(first_page, ('page', 'totalPages', {int})) or 1

        entries = InAdvancePagedList(
            lambda idx: self._entries(self._fetch_page(program_id, idx + 1) if idx else first_page),
            page_count, self._PAGE_SIZE)

        return self.playlist_result(entries, program_id, self._html_extract_title(program_page))