Added options to set download buffer size and disable automatic buffer resizing.
[youtube-dl] / youtube_dl / FileDownloader.py
index b234f185701e0194bca822a88747192ea56b1974..724de17c7be0dd05a73bcff4ce55bd18ca5b9f57 100644 (file)
@@ -14,7 +14,7 @@ import urllib2
 if os.name == 'nt':
        import ctypes
        
-from Utils import *
+from utils import *
 
 
 class FileDownloader(object):
@@ -61,6 +61,8 @@ class FileDownloader(object):
        ratelimit:        Download speed limit, in bytes/sec.
        nooverwrites:     Prevent overwriting files.
        retries:          Number of times to retry for HTTP error 5xx
+       buffersize:       Size of download buffer in bytes.
+       noresizebuffer:   Do not automatically resize the download buffer.
        continuedl:       Try to continue downloads if possible.
        noprogress:       Do not print the progress bar.
        playliststart:    Playlist item to start at.
@@ -344,6 +346,8 @@ class FileDownloader(object):
        def process_info(self, info_dict):
                """Process a single dictionary returned by an InfoExtractor."""
 
+               info_dict['stitle'] = sanitize_filename(info_dict['title'])
+
                reason = self._match_entry(info_dict)
                if reason is not None:
                        self.to_screen(u'[download] ' + reason)
@@ -470,7 +474,13 @@ class FileDownloader(object):
                                suitable_found = True
 
                                # Extract information from URL and process it
-                               ie.extract(url)
+                               videos = ie.extract(url)
+                               for video in videos or []:
+                                       try:
+                                               self.increment_downloads()
+                                               self.process_info(video)
+                                       except UnavailableVideoError:
+                                               self.trouble(u'\nERROR: unable to download video')
 
                                # Suitable InfoExtractor had been found; go to next URL
                                break
@@ -625,7 +635,7 @@ class FileDownloader(object):
                        data_len = long(data_len) + resume_len
                data_len_str = self.format_bytes(data_len)
                byte_counter = 0 + resume_len
-               block_size = 1024
+               block_size = self.params.get('buffersize', 1024)
                start = time.time()
                while True:
                        # Download and write
@@ -651,7 +661,8 @@ 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, len(data_block))
+                       if not self.params.get('noresizebuffer', False):
+                               block_size = self.best_block_size(after - before, len(data_block))
 
                        # Progress message
                        speed_str = self.calc_speed(start, time.time(), byte_counter - resume_len)