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

Code before:
            'title': 'md5:79f9c8183ea6a35c836923142cf0abcc',
            'description': '',
            'thumbnail': 'https://cdn.jwplayer.com/v2/media/W86PgQDn/thumbnails/B9gpIxkH.jpg',
            'channel': 'León Picarón',
            'channel_id': 'leonpicaron',
            'timestamp': 1696460362,
            'upload_date': '20231004',
        },
    }, {
        'url': 'https://piramide.tv/video/wcYn6li79NgN',
        'info_dict': {
            'id': 'wcYn6li79NgN',
            'ext': 'mp4',
            'title': 'ACEPTO TENER UN BEBE CON MI NOVIA\u2026? | Parte 1',
            'description': '',
            'channel': 'ARTA GAME',
            'channel_id': 'arta_game',
            'thumbnail': 'https://cdn.jwplayer.com/v2/media/cnEdGp5X/thumbnails/rHAaWfP7.jpg',
            'timestamp': 1703434976,
            'upload_date': '20231224',
        },
    }]

    def _extract_video(self, video_id):
        if video_data := self._download_json(
                f'https://hermes.piramide.tv/video/data/{video_id}', video_id, fatal=False):
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                f'https://cdn.piramide.tv/video/{video_id}/manifest.m3u8', video_id, fatal=False)
            next_video = traverse_obj(video_data, ('video', 'next_video', 'id', {str}))
            return next_video, {
                'id': video_id,
                'formats': formats,
                'subtitles': subtitles,
                'webpage_url': f'https://piramide.tv/video/{video_id}',
                'original_url': f'https://piramide.tv/video/{video_id}',
                **traverse_obj(video_data, ('video', {
                    'id': ('id', {str}),
                    'title': ('title', {str}),
                    'description': ('description', {str}),
                    'thumbnail': ('media', 'thumbnail', {url_or_none}),
                    'channel': ('channel', 'name', {str}),
                    'channel_id': ('channel', 'id', {str}),
                    'timestamp': ('date', {parse_iso8601}),
                })),
            }
        return None, {'id': video_id}

    def _entries(self, video_id):
        visited = set()
        while True:
            next_video, info = self._extract_video(video_id)

Review comment (bug):
Because fatal=False, error will not be raised when download_json fails if the video id does not exist. extract_m3u8_formats_and_subtitles will wait until timeout. This change is made to skip the process if video_data is not available.



Code after:
            'title': 'md5:79f9c8183ea6a35c836923142cf0abcc',
            'description': '',
            'thumbnail': 'https://cdn.jwplayer.com/v2/media/W86PgQDn/thumbnails/B9gpIxkH.jpg',
            'channel': 'León Picarón',
            'channel_id': 'leonpicaron',
            'timestamp': 1696460362,
            'upload_date': '20231004',
        },
    }, {
        'url': 'https://piramide.tv/video/wcYn6li79NgN',
        'info_dict': {
            'id': 'wcYn6li79NgN',
            'ext': 'mp4',
            'title': 'ACEPTO TENER UN BEBE CON MI NOVIA\u2026? | Parte 1',
            'description': '',
            'channel': 'ARTA GAME',
            'channel_id': 'arta_game',
            'thumbnail': 'https://cdn.jwplayer.com/v2/media/cnEdGp5X/thumbnails/rHAaWfP7.jpg',
            'timestamp': 1703434976,
            'upload_date': '20231224',
        },
    }]

    def _extract_video(self, video_id):
        video_data = self._download_json(
            f'https://hermes.piramide.tv/video/data/{video_id}', video_id, fatal=False)
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            f'https://cdn.piramide.tv/video/{video_id}/manifest.m3u8', video_id, fatal=False)
        next_video = traverse_obj(video_data, ('video', 'next_video', 'id', {str}))
        return next_video, {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(video_data, ('video', {
                'id': ('id', {str}),
                'title': ('title', {str}),
                'description': ('description', {str}),
                'thumbnail': ('media', 'thumbnail', {url_or_none}),
                'channel': ('channel', 'name', {str}),
                'channel_id': ('channel', 'id', {str}),
                'timestamp': ('date', {parse_iso8601}),
            })),
        }

    def _entries(self, video_id):
        visited = set()
        while True:
            visited.add(video_id)
            next_video, info = self._extract_video(video_id)
            yield info
            if not next_video or next_video in visited: