diff --git a/gallery_dl/downloader/ytdl.py b/gallery_dl/downloader/ytdl.py index 2126e107..6ac3ee08 100644 --- a/gallery_dl/downloader/ytdl.py +++ b/gallery_dl/downloader/ytdl.py @@ -30,6 +30,7 @@ class YoutubeDLDownloader(DownloaderBase): } self.ytdl_instance = None + self.rate = None self.forward_cookies = self.config("forward-cookies", True) self.progress = self.config("progress", 3.0) self.outtmpl = self.config("outtmpl") @@ -70,6 +71,9 @@ class YoutubeDLDownloader(DownloaderBase): if self.progress is not None and not ytdl_instance._progress_hooks: ytdl_instance.add_progress_hook(self._progress_hook) + if rl := ytdl_instance.params.pop("_gdl_ratelimit", False): + self.rate = rl + info_dict = kwdict.pop("_ytdl_info_dict", None) if not info_dict: url = url[5:] @@ -132,6 +136,9 @@ class YoutubeDLDownloader(DownloaderBase): pathfmt.temppath = "" return True + if self.rate is not None: + ytdl_instance.params["ratelimit"] = self.rate() + self.out.start(pathfmt.path) if self.part: pathfmt.kwdict["extension"] = pathfmt.prefix @@ -161,6 +168,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() ytdl_instance.process_info(entry) return True diff --git a/gallery_dl/ytdl.py b/gallery_dl/ytdl.py index fa948f2c..f47c5020 100644 --- a/gallery_dl/ytdl.py +++ b/gallery_dl/ytdl.py @@ -49,18 +49,20 @@ def construct_YoutubeDL(module, obj, user_opts, system_opts=None): opts["nopart"] = not config("part", True) if opts.get("updatetime") is None: opts["updatetime"] = config("mtime", True) - if opts.get("ratelimit") is None: - rate = config("rate") - if rate: - func = util.build_selection_func(rate, 0, text.parse_bytes) - rmax = func.args[1] if hasattr(func, "args") else func() - opts["ratelimit"] = rmax or None - else: - opts["ratelimit"] = None if opts.get("min_filesize") is None: opts["min_filesize"] = text.parse_bytes(config("filesize-min"), None) if opts.get("max_filesize") is None: opts["max_filesize"] = text.parse_bytes(config("filesize-max"), None) + if opts.get("ratelimit") is None: + rate = config("rate") + if rate: + func = util.build_selection_func(rate, 0, text.parse_bytes) + if hasattr(func, "args"): + opts["_gdl_ratelimit"] = func + else: + opts["ratelimit"] = func() or None + else: + opts["ratelimit"] = None raw_opts = config("raw-options") if raw_opts: