Take into account resume_len when calculating speed and ETA
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>
Wed, 15 Dec 2010 20:42:11 +0000 (21:42 +0100)
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>
Wed, 15 Dec 2010 20:42:11 +0000 (21:42 +0100)
youtube-dl

index 7d4344ae03e0ccaed3f455ae178de8828037b070..cf0e9fcb8a2b0117e87d635141836d2765dda881 100755 (executable)
@@ -617,10 +617,9 @@ class FileDownloader(object):
                        before = time.time()
                        data_block = data.read(block_size)
                        after = time.time()
-                       data_block_len = len(data_block)
-                       if data_block_len == 0:
+                       if len(data_block) == 0:
                                break
-                       byte_counter += data_block_len
+                       byte_counter += len(data_block)
 
                        # Open file just in time
                        if stream is None:
@@ -635,16 +634,16 @@ class FileDownloader(object):
                        except (IOError, OSError), err:
                                self.trouble(u'\nERROR: unable to write data: %s' % str(err))
                                return False
-                       block_size = self.best_block_size(after - before, data_block_len)
+                       block_size = self.best_block_size(after - before, len(data_block))
 
                        # Progress message
                        percent_str = self.calc_percent(byte_counter, data_len)
-                       eta_str = self.calc_eta(start, time.time(), data_len, byte_counter)
-                       speed_str = self.calc_speed(start, time.time(), byte_counter)
+                       eta_str = self.calc_eta(start, time.time(), data_len - resume_len, byte_counter - resume_len)
+                       speed_str = self.calc_speed(start, time.time(), byte_counter - resume_len)
                        self.report_progress(percent_str, data_len_str, speed_str, eta_str)
 
                        # Apply rate limit
-                       self.slow_down(start, byte_counter)
+                       self.slow_down(start, byte_counter - resume_len)
 
                stream.close()
                self.report_finish()