aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2024-02-25 06:03:57 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2024-02-25 06:06:42 +0530
commit069b2aedae2279668b6051627a81fc4fbd9c146a (patch)
tree237ccbbcdffcf240f0bab5cfa90ec752e8f837df
parent5eedc208ec89d6284777060c94aadd06502338b9 (diff)
Create `ydl._request_director` when needed
-rw-r--r--yt_dlp/YoutubeDL.py6
-rw-r--r--yt_dlp/networking/common.py1
2 files changed, 6 insertions, 1 deletions
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py
index 99b3ea8c2..ef66306b1 100644
--- a/yt_dlp/YoutubeDL.py
+++ b/yt_dlp/YoutubeDL.py
@@ -690,7 +690,6 @@ class YoutubeDL:
self.params['http_headers'] = HTTPHeaderDict(std_headers, self.params.get('http_headers'))
self._load_cookies(self.params['http_headers'].get('Cookie')) # compat
self.params['http_headers'].pop('Cookie', None)
- self._request_director = self.build_request_director(_REQUEST_HANDLERS.values(), _RH_PREFERENCES)
if auto_init and auto_init != 'no_verbose_header':
self.print_debug_header()
@@ -964,6 +963,7 @@ class YoutubeDL:
def close(self):
self.save_cookies()
self._request_director.close()
+ del self._request_director
def trouble(self, message=None, tb=None, is_error=True):
"""Determine action to take when a download problem appears.
@@ -4160,6 +4160,10 @@ class YoutubeDL:
director.preferences.add(lambda rh, _: 500 if rh.RH_KEY == 'Urllib' else 0)
return director
+ @functools.cached_property
+ def _request_director(self):
+ return self.build_request_director(_REQUEST_HANDLERS.values(), _RH_PREFERENCES)
+
def encode(self, s):
if isinstance(s, bytes):
return s # Already encoded
diff --git a/yt_dlp/networking/common.py b/yt_dlp/networking/common.py
index 584c7bb4d..7da2652ae 100644
--- a/yt_dlp/networking/common.py
+++ b/yt_dlp/networking/common.py
@@ -68,6 +68,7 @@ class RequestDirector:
def close(self):
for handler in self.handlers.values():
handler.close()
+ self.handlers = {}
def add_handler(self, handler: RequestHandler):
"""Add a handler. If a handler of the same RH_KEY exists, it will overwrite it"""