A feature-rich command-line audio/video downloader
[utils] Improve performance using `functools.cache`
pukkandan0b9c08b47bb5
diff --git a/yt_dlp/compat/functools.py b/yt_dlp/compat/functools.pynew file mode 100644index 0000000000..36c983642d--- /dev/null+++ b/yt_dlp/compat/functools.py@@ -0,0 +1,12 @@+# flake8: noqa: F405+from functools import * # noqa: F403++from .compat_utils import passthrough_module++passthrough_module(__name__, 'functools')+del passthrough_module++try:+ cache # >= 3.9+except NameError:+ cache = lru_cache(maxsize=None)diff --git a/yt_dlp/update.py b/yt_dlp/update.pyindex 8dcf260f5c..d627ae269a 100644--- a/yt_dlp/update.py+++ b/yt_dlp/update.py@@ -7,11 +7,12 @@ import sysimport tracebackfrom zipimport import zipimporter-from .compat import compat_realpath+from .compat import compat_realpath, functoolsfrom .utils import Popen, encode_compat_str, write_stringfrom .version import __version__def detect_variant():if hasattr(sys, 'frozen'):prefix = 'mac' if sys.platform == 'darwin' else 'win'diff --git a/yt_dlp/utils.py b/yt_dlp/utils.pyindex 41157f5de4..0274e330d3 100644--- a/yt_dlp/utils.py+++ b/yt_dlp/utils.py@@ -11,7 +11,6 @@ import datetimeimport email.headerimport email.utilsimport errno-import functoolsimport gzipimport hashlibimport hmac@@ -39,8 +38,8 @@ import urllib.parseimport xml.etree.ElementTreeimport zlib+from .compat import asyncio, functools # Modulesfrom .compat import (- asyncio,compat_chr,compat_cookiejar,compat_etree_fromstring,@@ -248,6 +247,7 @@ JSON_LD_RE = r'(?is)<script[^>]+type=(["\']?)application/ld\+json\1[^>]*>(?P<jsoNUMBER_RE = r'\d+(?:\.\d+)?'def preferredencoding():"""Get preferred encoding.@@ -1883,6 +1883,7 @@ def platform_name():return resdef get_windows_version():''' Get Windows version. None if it's not running on Windows '''if compat_os_name == 'nt':@@ -2079,6 +2080,7 @@ class locked_file:return iter(self.f)def get_filesystem_encoding():encoding = sys.getfilesystemencoding()return encoding if encoding is not None else 'utf-8'@@ -5092,6 +5094,7 @@ def jwt_decode_hs256(jwt):return payload_datadef supports_terminal_sequences(stream):if compat_os_name == 'nt':from .compat import WINDOWS_VT_MODE # Must be imported locally