[dl] improve maximum 'rate' detection (#7638)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user