A feature-rich command-line audio/video downloader
[utils] Add `WINDOWS_VT_MODE` to globals (#12460)
Simon Sawickieed94c7306d4
diff --git a/test/test_compat.py b/test/test_compat.pyindex b1cc2a8187..3aa9c0c518 100644--- a/test/test_compat.py+++ b/test/test_compat.py@@ -21,9 +21,6 @@ class TestCompat(unittest.TestCase):with self.assertWarns(DeprecationWarning):_ = compat.compat_basestring- with self.assertWarns(DeprecationWarning):- _ = compat.WINDOWS_VT_MODE-self.assertEqual(urllib.request.getproxies, getproxies)with self.assertWarns(DeprecationWarning):diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.pyindex 76fd18c338..a9f347bf4a 100644--- a/yt_dlp/YoutubeDL.py+++ b/yt_dlp/YoutubeDL.py@@ -36,6 +36,7 @@ from .extractor.openload import PhantomJSwrapperfrom .globals import (IN_CLI,LAZY_EXTRACTORS,+ WINDOWS_VT_MODE,plugin_ies,plugin_ies_overrides,plugin_pps,@@ -4040,8 +4041,7 @@ class YoutubeDL:if os.environ.get('TERM', '').lower() == 'dumb':additional_info.append('dumb')if not supports_terminal_sequences(stream):- from .utils import WINDOWS_VT_MODE # Must be imported locally- additional_info.append('No VT' if WINDOWS_VT_MODE is False else 'No ANSI')+ additional_info.append('No VT' if WINDOWS_VT_MODE.value is False else 'No ANSI')if additional_info:ret = f'{ret} ({",".join(additional_info)})'return retdiff --git a/yt_dlp/compat/_legacy.py b/yt_dlp/compat/_legacy.pyindex dae2c14592..2f3e35d4a8 100644--- a/yt_dlp/compat/_legacy.py+++ b/yt_dlp/compat/_legacy.py@@ -37,7 +37,7 @@ from ..dependencies import websockets as compat_websockets # noqa: F401from ..dependencies.Cryptodome import AES as compat_pycrypto_AES # noqa: F401from ..networking.exceptions import HTTPError as compat_HTTPError-passthrough_module(__name__, '...utils', ('WINDOWS_VT_MODE', 'windows_enable_vt_mode'))+passthrough_module(__name__, '...utils', ('windows_enable_vt_mode',))# compat_ctypes_WINFUNCTYPE = ctypes.WINFUNCTYPEdiff --git a/yt_dlp/globals.py b/yt_dlp/globals.pyindex 0cf276cc9e..81ad004480 100644--- a/yt_dlp/globals.py+++ b/yt_dlp/globals.py@@ -1,3 +1,4 @@+import osfrom collections import defaultdict# Please Note: Due to necessary changes and the complex nature involved in the plugin/globals system,@@ -28,3 +29,4 @@ plugin_ies_overrides = Indirect(defaultdict(list))# MiscIN_CLI = Indirect(False)LAZY_EXTRACTORS = Indirect(None) # `False`=force, `None`=disabled, `True`=enabled+WINDOWS_VT_MODE = Indirect(False if os.name == 'nt' else None)diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.pyindex 7d79f417fa..1cb62712ba 100644--- a/yt_dlp/utils/_utils.py+++ b/yt_dlp/utils/_utils.py@@ -52,7 +52,7 @@ from ..compat import (compat_HTMLParseError,)from ..dependencies import xattr-from ..globals import IN_CLI+from ..globals import IN_CLI, WINDOWS_VT_MODE__name__ = __name__.rsplit('.', 1)[0] # noqa: A001 # Pretend to be the parent module@@ -4759,13 +4759,10 @@ def jwt_decode_hs256(jwt):return json.loads(base64.urlsafe_b64decode(f'{payload_b64}==='))-WINDOWS_VT_MODE = False if os.name == 'nt' else None--@functools.cachedef supports_terminal_sequences(stream):if os.name == 'nt':- if not WINDOWS_VT_MODE:+ if not WINDOWS_VT_MODE.value:return Falseelif not os.getenv('TERM'):return False@@ -4802,8 +4799,7 @@ def windows_enable_vt_mode():finally:os.close(handle)- global WINDOWS_VT_MODE- WINDOWS_VT_MODE = True+ WINDOWS_VT_MODE.value = Truesupports_terminal_sequences.cache_clear()