mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-12-27 21:59:17 +01:00
Create ydl._request_director
when needed
This commit is contained in:
parent
5eedc208ec
commit
069b2aedae
2 changed files with 6 additions and 1 deletions
|
@ -690,7 +690,6 @@ class YoutubeDL:
|
||||||
self.params['http_headers'] = HTTPHeaderDict(std_headers, self.params.get('http_headers'))
|
self.params['http_headers'] = HTTPHeaderDict(std_headers, self.params.get('http_headers'))
|
||||||
self._load_cookies(self.params['http_headers'].get('Cookie')) # compat
|
self._load_cookies(self.params['http_headers'].get('Cookie')) # compat
|
||||||
self.params['http_headers'].pop('Cookie', None)
|
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':
|
if auto_init and auto_init != 'no_verbose_header':
|
||||||
self.print_debug_header()
|
self.print_debug_header()
|
||||||
|
@ -964,6 +963,7 @@ class YoutubeDL:
|
||||||
def close(self):
|
def close(self):
|
||||||
self.save_cookies()
|
self.save_cookies()
|
||||||
self._request_director.close()
|
self._request_director.close()
|
||||||
|
del self._request_director
|
||||||
|
|
||||||
def trouble(self, message=None, tb=None, is_error=True):
|
def trouble(self, message=None, tb=None, is_error=True):
|
||||||
"""Determine action to take when a download problem appears.
|
"""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)
|
director.preferences.add(lambda rh, _: 500 if rh.RH_KEY == 'Urllib' else 0)
|
||||||
return director
|
return director
|
||||||
|
|
||||||
|
@functools.cached_property
|
||||||
|
def _request_director(self):
|
||||||
|
return self.build_request_director(_REQUEST_HANDLERS.values(), _RH_PREFERENCES)
|
||||||
|
|
||||||
def encode(self, s):
|
def encode(self, s):
|
||||||
if isinstance(s, bytes):
|
if isinstance(s, bytes):
|
||||||
return s # Already encoded
|
return s # Already encoded
|
||||||
|
|
|
@ -68,6 +68,7 @@ class RequestDirector:
|
||||||
def close(self):
|
def close(self):
|
||||||
for handler in self.handlers.values():
|
for handler in self.handlers.values():
|
||||||
handler.close()
|
handler.close()
|
||||||
|
self.handlers = {}
|
||||||
|
|
||||||
def add_handler(self, handler: RequestHandler):
|
def add_handler(self, handler: RequestHandler):
|
||||||
"""Add a handler. If a handler of the same RH_KEY exists, it will overwrite it"""
|
"""Add a handler. If a handler of the same RH_KEY exists, it will overwrite it"""
|
||||||
|
|
Loading…
Reference in a new issue