From 253ac4ba6af5d2617275d258d259bcc2c8fa391a Mon Sep 17 00:00:00 2001 From: mzhou Date: Sat, 7 Jan 2023 04:30:42 +0900 Subject: [PATCH] [extractor/youtube] Retry manifest refresh for live-from-start (#5670) Avoids ending download early when live stream is temporarily offline. Best used with somewhat large `--retry-sleep extractor:` and `--extractor-retries` Authored by: mzhou --- yt_dlp/extractor/youtube.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 2fd61c871..855a76012 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -2650,18 +2650,19 @@ class YoutubeIE(YoutubeBaseInfoExtractor): """ @returns (manifest_url, manifest_stream_number, is_live) or None """ - with lock: - refetch_manifest(format_id, delay) - - f = next((f for f in formats if f['format_id'] == format_id), None) - if not f: - if not is_live: - self.to_screen(f'{video_id}: Video is no longer live') - else: - self.report_warning( - f'Cannot find refreshed manifest for format {format_id}{bug_reports_message()}') - return None - return f['manifest_url'], f['manifest_stream_number'], is_live + for retry in self.RetryManager(fatal=False): + with lock: + refetch_manifest(format_id, delay) + + f = next((f for f in formats if f['format_id'] == format_id), None) + if not f: + if not is_live: + retry.error = f'{video_id}: Video is no longer live' + else: + retry.error = f'Cannot find refreshed manifest for format {format_id}{bug_reports_message()}' + continue + return f['manifest_url'], f['manifest_stream_number'], is_live + return None for f in formats: f['is_live'] = is_live