diff --git a/yt_dlp/compat/functools.py b/yt_dlp/compat/functools.py index 36c983642d..c3c4d8f486 100644 --- a/yt_dlp/compat/functools.py +++ b/yt_dlp/compat/functools.py @@ -10,3 +10,15 @@ try: cache # >= 3.9 except NameError: cache = lru_cache(maxsize=None) + +try: + cached_property # >= 3.8 +except NameError: + class cached_property: + def __init__(self, func): + update_wrapper(self, func) + self.func = func + + def __get__(self, instance, _): + setattr(instance, self.func.__name__, self.func(instance)) + return getattr(instance, self.func.__name__) diff --git a/yt_dlp/downloader/common.py b/yt_dlp/downloader/common.py index 276675532f..d74692130d 100644 --- a/yt_dlp/downloader/common.py +++ b/yt_dlp/downloader/common.py @@ -11,6 +11,7 @@ from ..minicurses import ( MultilinePrinter, QuietMultilinePrinter, ) +from ..compat import functools from ..utils import ( NUMBER_RE, LockingUnsupportedError, @@ -102,7 +103,7 @@ class FileDownloader: __to_screen = to_screen - @property + @functools.cached_property def FD_NAME(self): return re.sub(r'(?