A feature-rich command-line audio/video downloader
[utils] sanitize_open: Allow any IO stream as stdout
pukkandandaef7911000b
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.pyindex fcc25388d8..bdab9fb499 100644--- a/yt_dlp/utils.py+++ b/yt_dlp/utils.py@@ -598,7 +598,9 @@ def sanitize_open(filename, open_mode):if filename == '-':if sys.platform == 'win32':import msvcrt- msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)+ # stdout may be any IO stream. Eg, when using contextlib.redirect_stdout+ with contextlib.suppress(io.UnsupportedOperation):+ msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)return (sys.stdout.buffer if hasattr(sys.stdout, 'buffer') else sys.stdout, filename)for attempt in range(2):