From: Philipp Hagemeister Date: Fri, 12 Dec 2014 16:16:13 +0000 (+0100) Subject: Merge remote-tracking branch 'SyxbEaEQ2/rate-limit' X-Git-Url: http://git.oshgnacknak.de/?a=commitdiff_plain;h=cf372f0778e82cdc181a6173909589e640ac29fb;p=youtube-dl Merge remote-tracking branch 'SyxbEaEQ2/rate-limit' --- cf372f0778e82cdc181a6173909589e640ac29fb diff --cc youtube_dl/downloader/http.py index 8491cee8a,462be2739..224962e86 --- a/youtube_dl/downloader/http.py +++ b/youtube_dl/downloader/http.py @@@ -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)) @@@ -186,15 -194,11 +202,12 @@@ 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))