Merge remote-tracking branch 'SyxbEaEQ2/rate-limit'
authorPhilipp Hagemeister <phihag@phihag.de>
Fri, 12 Dec 2014 16:16:13 +0000 (17:16 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Fri, 12 Dec 2014 16:16:13 +0000 (17:16 +0100)
1  2 
youtube_dl/downloader/common.py
youtube_dl/downloader/http.py

Simple merge
index 8491cee8aa2769e8465176411a92ded85b07ad13,462be2739143e19ea27406731c069ca461787b41..224962e86827956b2145378b7a6cf920a02029e6
@@@ -158,9 -155,18 +163,18 @@@ class HttpFD(FileDownloader)
              try:
                  stream.write(data_block)
              except (IOError, OSError) as err:
 -                self.to_stderr(u"\n")
 -                self.report_error(u'unable to write data: %s' % str(err))
 +                self.to_stderr('\n')
 +                self.report_error('unable to write data: %s' % str(err))
                  return False
+             # Apply rate limit
+             self.slow_down(start, now, byte_counter - resume_len)
+             # end measuring of one loop run
+             now = time.time()
+             after = now
+             # Adjust block size
              if not self.params.get('noresizebuffer', False):
                  block_size = self.best_block_size(after - before, len(data_block))
  
              if is_test and byte_counter == data_len:
                  break
  
-             # Apply rate limit
-             self.slow_down(start, byte_counter - resume_len)
          if stream is None:
 -            self.to_stderr(u"\n")
 -            self.report_error(u'Did not get any data blocks')
 +            self.to_stderr('\n')
 +            self.report_error('Did not get any data blocks')
              return False
 -        stream.close()
 +        if tmpfilename != '-':
 +            stream.close()
          self.report_finish(data_len_str, (time.time() - start))
          if data_len is not None and byte_counter != data_len:
              raise ContentTooShortError(byte_counter, int(data_len))