From e3c7d49571b39e5886ff5371a0dd99dca0709191 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Wed, 8 Dec 2021 19:41:54 +0530 Subject: [PATCH] [compat] Suppress errors in enabling VT mode Closes #1932 --- yt_dlp/YoutubeDL.py | 3 ++- yt_dlp/compat.py | 11 ++++++++++- yt_dlp/utils.py | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 7406f4c5e..6064c4c95 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -3394,7 +3394,8 @@ def print_debug_header(self): def get_encoding(stream): ret = getattr(stream, 'encoding', 'missing (%s)' % type(stream).__name__) if not supports_terminal_sequences(stream): - ret += ' (No ANSI)' + from .compat import WINDOWS_VT_MODE + ret += ' (No VT)' if WINDOWS_VT_MODE is False else ' (No ANSI)' return ret encoding_str = 'Encodings: locale %s, fs %s, out %s, err %s, pref %s' % ( diff --git a/yt_dlp/compat.py b/yt_dlp/compat.py index 8508f1465..79c8e3494 100644 --- a/yt_dlp/compat.py +++ b/yt_dlp/compat.py @@ -160,12 +160,20 @@ def compat_expanduser(path): compat_pycrypto_AES = None +WINDOWS_VT_MODE = False if compat_os_name == 'nt' else None + + def windows_enable_vt_mode(): # TODO: Do this the proper way https://bugs.python.org/issue30075 if compat_os_name != 'nt': return + global WINDOWS_VT_MODE startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - subprocess.Popen('', shell=True, startupinfo=startupinfo) + try: + subprocess.Popen('', shell=True, startupinfo=startupinfo) + WINDOWS_VT_MODE = True + except Exception: + pass # Deprecated @@ -226,6 +234,7 @@ def windows_enable_vt_mode(): # TODO: Do this the proper way https://bugs.pytho # Set public objects __all__ = [ + 'WINDOWS_VT_MODE', 'compat_HTMLParseError', 'compat_HTMLParser', 'compat_HTTPError', diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 6831f0773..15cc4d3b2 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -6592,7 +6592,8 @@ def jwt_decode_hs256(jwt): def supports_terminal_sequences(stream): if compat_os_name == 'nt': - if get_windows_version() < (10, 0, 10586): + from .compat import WINDOWS_VT_MODE # Must be imported locally + if not WINDOWS_VT_MODE or get_windows_version() < (10, 0, 10586): return False elif not os.getenv('TERM'): return False