[ytdl] use '__gdl_initialize' key to trigger init code
This commit is contained in:
@@ -30,7 +30,7 @@ class YoutubeDLDownloader(DownloaderBase):
|
||||
}
|
||||
|
||||
self.ytdl_instance = None
|
||||
self.rate = None
|
||||
self.rate_dyn = None
|
||||
self.forward_cookies = self.config("forward-cookies", True)
|
||||
self.progress = self.config("progress", 3.0)
|
||||
self.outtmpl = self.config("outtmpl")
|
||||
@@ -68,11 +68,13 @@ class YoutubeDLDownloader(DownloaderBase):
|
||||
for cookie in self.session.cookies:
|
||||
set_cookie(cookie)
|
||||
|
||||
if self.progress is not None and not ytdl_instance._progress_hooks:
|
||||
ytdl_instance.add_progress_hook(self._progress_hook)
|
||||
if "__gdl_initialize" in ytdl_instance.params:
|
||||
del ytdl_instance.params["__gdl_initialize"]
|
||||
|
||||
if rl := ytdl_instance.params.pop("_gdl_ratelimit", False):
|
||||
self.rate = rl
|
||||
if self.progress is not None:
|
||||
ytdl_instance.add_progress_hook(self._progress_hook)
|
||||
if rlf := ytdl_instance.params.pop("__gdl_ratelimit_func", False):
|
||||
self.rate_dyn = rlf
|
||||
|
||||
info_dict = kwdict.pop("_ytdl_info_dict", None)
|
||||
if not info_dict:
|
||||
@@ -136,8 +138,9 @@ class YoutubeDLDownloader(DownloaderBase):
|
||||
pathfmt.temppath = ""
|
||||
return True
|
||||
|
||||
if self.rate is not None:
|
||||
ytdl_instance.params["ratelimit"] = self.rate()
|
||||
if self.rate_dyn is not None:
|
||||
# static ratelimits are set in ytdl.construct_YoutubeDL
|
||||
ytdl_instance.params["ratelimit"] = self.rate_dyn()
|
||||
|
||||
self.out.start(pathfmt.path)
|
||||
if self.part:
|
||||
@@ -168,8 +171,8 @@ class YoutubeDLDownloader(DownloaderBase):
|
||||
self._set_outtmpl(ytdl_instance, pathfmt.realpath)
|
||||
|
||||
for entry in info_dict["entries"]:
|
||||
if self.rate is not None:
|
||||
ytdl_instance.params["ratelimit"] = self.rate()
|
||||
if self.rate_dyn is not None:
|
||||
ytdl_instance.params["ratelimit"] = self.rate_dyn()
|
||||
ytdl_instance.process_info(entry)
|
||||
return True
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ def construct_YoutubeDL(module, obj, user_opts, system_opts=None):
|
||||
if rate:
|
||||
func = util.build_selection_func(rate, 0, text.parse_bytes)
|
||||
if hasattr(func, "args"):
|
||||
opts["_gdl_ratelimit"] = func
|
||||
opts["__gdl_ratelimit_func"] = func
|
||||
else:
|
||||
opts["ratelimit"] = func() or None
|
||||
else:
|
||||
@@ -72,6 +72,7 @@ def construct_YoutubeDL(module, obj, user_opts, system_opts=None):
|
||||
if system_opts:
|
||||
opts.update(system_opts)
|
||||
|
||||
opts["__gdl_initialize"] = True
|
||||
return module.YoutubeDL(opts)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user