Skip to content

A feature-rich command-line audio/video downloader

[core] Don't let format testing alter the return code (#13767)

bashonly4919051e447c
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py
index 44a6696c02..3cfcb8ef0f 100644
--- a/yt_dlp/YoutubeDL.py
+++ b/yt_dlp/YoutubeDL.py
@@ -2208,6 +2208,9 @@ class YoutubeDL:
continue
temp_file = tempfile.NamedTemporaryFile(suffix='.tmp', delete=False, dir=path or None)
temp_file.close()
+ # If FragmentFD fails when testing a fragment, it will wrongly set a non-zero return code.
+ # Save the actual return code for later. See https://github.com/yt-dlp/yt-dlp/issues/13750
+ original_retcode = self._download_retcode
try:
success, _ = self.dl(temp_file.name, f, test=True)
except (DownloadError, OSError, ValueError, *network_exceptions):
@@ -2218,6 +2221,8 @@ class YoutubeDL:
os.remove(temp_file.name)
except OSError:
self.report_warning(f'Unable to delete temporary file "{temp_file.name}"')
+ # Restore the actual return code
+ self._download_retcode = original_retcode
f['__working'] = success
if success:
f.pop('__needs_testing', None)