diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-07-31 03:31:20 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-07-31 03:31:20 +0530 |
commit | daef7911000bea69407667de8193eafcdcdad36b (patch) | |
tree | 9c9b9d8697038f3fec25d0d187f089a85b8299a1 | |
parent | a6bcaf71fc94b2f301d4253ecea87ea2ff76fedb (diff) | |
download | hypervideo-pre-daef7911000bea69407667de8193eafcdcdad36b.tar.lz hypervideo-pre-daef7911000bea69407667de8193eafcdcdad36b.tar.xz hypervideo-pre-daef7911000bea69407667de8193eafcdcdad36b.zip |
[utils] sanitize_open: Allow any IO stream as stdout
Fixes: https://github.com/yt-dlp/yt-dlp/issues/3298#issuecomment-1181754989
-rw-r--r-- | yt_dlp/utils.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index fcc25388d..bdab9fb49 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): |