diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index db95ce6a..101baced 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -69,11 +69,11 @@ class HttpDownloader(DownloaderBase): self.chunk_size = chunk_size if self.rate: func = util.build_selection_func(self.rate, 0, text.parse_bytes) - value = func() - if value: - # wrong when func() returns from a range - if value < self.chunk_size: - self.chunk_size = value + rmax = func.args[1] if hasattr(func, "args") else func() + if rmax: + if rmax < self.chunk_size: + # reduce chunk_size to allow for one iteration each second + self.chunk_size = rmax self.rate = func self.receive = self._receive_rate else: diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 9fff88cb..38be8ac5 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -906,18 +906,17 @@ def build_selection_func(value, min=0.0, conv=float): if isinstance(value, str): lower, _, upper = value.partition("-") - lower = conv(lower) else: try: lower, upper = value except TypeError: lower, upper = value, None - lower = conv(lower) + lower = conv(lower) if upper: upper = conv(upper) return functools.partial( - random.uniform if min.__class__ is float else random.randint, + random.uniform if lower.__class__ is float else random.randint, lower if lower > min else min, upper if upper > min else min, ) diff --git a/gallery_dl/ytdl.py b/gallery_dl/ytdl.py index 29ab5267..8dd86421 100644 --- a/gallery_dl/ytdl.py +++ b/gallery_dl/ytdl.py @@ -54,7 +54,8 @@ def construct_YoutubeDL(module, obj, user_opts, system_opts=None): rate = config("rate") if rate: func = util.build_selection_func(rate, 0, text.parse_bytes) - opts["ratelimit"] = func() or None + 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: