]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[downloader/common] Improve rate limit (#21301)
authorSergey M․ <dstftw@gmail.com>
Tue, 4 Jun 2019 20:06:35 +0000 (03:06 +0700)
committerSergey M․ <dstftw@gmail.com>
Tue, 4 Jun 2019 20:06:35 +0000 (03:06 +0700)
youtube_dl/downloader/common.py

index 646d7f7795cc47c281db3033fa3a9df87a646ed2..1cdba89cd9b093c1cc45071d34e307028aac02ea 100644 (file)
@@ -176,7 +176,9 @@ class FileDownloader(object):
             return
         speed = float(byte_counter) / elapsed
         if speed > rate_limit:
-            time.sleep(max((byte_counter // rate_limit) - elapsed, 0))
+            sleep_time = float(byte_counter) / rate_limit - elapsed
+            if sleep_time > 0:
+                time.sleep(sleep_time)
 
     def temp_name(self, filename):
         """Returns a temporary filename for the given filename."""