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

Code before:
        if asset_id:
            hls_url = hydration['content']['currentContent']['base_url_hls'].replace('[node:field_asset_id]', asset_id)
        else:
            hls_url = traverse_obj(hydration, ('content', 'currentContent', 'channel', 'hls'))

        metadata = {
            'thumbnail': traverse_obj(
                hydration, ('content', 'currentContent', 'channel', 'image', 'logo', 'path'),
                ('content', 'currentContent', 'resource', 'image', 'cover_desktop', 'path')),
            **traverse_obj(hydration, ('content', 'currentContent', {
                'title': 'title',
                'description': 'description',
            })),
        }

        # Probably it's a program's page
        if not hls_url:
            seasons = traverse_obj(
                hydration, ('content', 'currentContent', 'widgets', lambda _, y: y['type'] == 'seasonList', 'contents'),
                get_all=False)
            if not seasons:
                podcast_episodes = traverse_obj(hydration, ('content', 'currentContent', 'audios'))
                if not podcast_episodes:
                    raise ExtractorError('Could not find asset_id nor program playlist nor podcast episodes')

                return self.playlist_result([self.url_result(episode['file'], **traverse_obj(episode, {
                    'title': 'title',
                    'description': 'description',
                    'episode_number': ('chapter_number', {lambda x: int_or_none(float_or_none(x))}),
                    'season_number': 'season',
                })) for episode in podcast_episodes], video_id, **metadata)

            entries = []
            for season in seasons:
                for episode in season['contents']:
                    entries.append(self.url_result(urljoin(url, episode['slug']), **{
                        **traverse_obj(season, {
                            'season': 'title',
                            'season_number': 'season',
                        }),
                        **traverse_obj(episode, {
                            'title': 'title',
                            'thumbnail': ('image', 'cover', 'path'),
                            'episode_number': 'chapter_number',
                        })
                    }))

            return self.playlist_result(entries, video_id, **metadata)

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(hls_url, video_id, 'mp4')


Review comment (refactor):
`url_transparent=True`, right? or else the entry metadata being passed is only for --flat-playlist?

Also, the test URL `https://www.rtvcplay.co/series-al-oido/diez-versiones` has its playlist result handed off to the generic extractor because the URLs are direct mp3 links. Should we be returning info_dict entries instead of url_results here?

Code after:

        hydration = self._search_json(
            r'window\.__RTVCPLAY_STATE__\s*=', webpage, 'hydration',
            video_id, transform_source=js_to_json)['content']['currentContent']

        asset_id = traverse_obj(hydration, ('video', 'assetid'))
        if asset_id:
            hls_url = hydration['base_url_hls'].replace('[node:field_asset_id]', asset_id)
        else:
            hls_url = traverse_obj(hydration, ('channel', 'hls'))

        metadata = traverse_obj(hydration, {
            'title': 'title',
            'description': 'description',
            'thumbnail': ((('channel', 'image', 'logo'), ('resource', 'image', 'cover_desktop')), 'path'),
        }, get_all=False)

        # Probably it's a program's page
        if not hls_url:
            seasons = traverse_obj(
                hydration, ('widgets', lambda _, y: y['type'] == 'seasonList', 'contents'),
                get_all=False)
            if not seasons:
                podcast_episodes = hydration.get('audios')
                if not podcast_episodes:
                    raise ExtractorError('Could not find asset_id nor program playlist nor podcast episodes')

                return self.playlist_result([
                    self.url_result(episode['file'], url_transparent=True, **traverse_obj(episode, {
                        'title': 'title',
                        'description': ('description', {clean_html}),
                        'episode_number': ('chapter_number', {float_or_none}, {int_or_none}),
                        'season_number': ('season', {int_or_none}),
                    })) for episode in podcast_episodes], video_id, **metadata)

            entries = [self.url_result(
                urljoin(url, episode['slug']), url_transparent=True,
                **traverse_obj(season, {
                    'season': 'title',
                    'season_number': ('season', {int_or_none}),
                }), **traverse_obj(episode, {
                    'title': 'title',
                    'thumbnail': ('image', 'cover', 'path'),
                    'episode_number': ('chapter_number', {int_or_none}),
                })) for season in seasons for episode in traverse_obj(season, ('contents', ...))]

            return self.playlist_result(entries, video_id, **metadata)

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(hls_url, video_id, 'mp4')

        return {