]> gitweb @ CieloNegro.org - youtube-dl.git/blobdiff - youtube-dl
Add .to_stderr() to downloaders
[youtube-dl.git] / youtube-dl
index adb4234c7be89d4507426d8cab3d66866474f0a5..1c4a05471e1eb7533cd2906b7dc2fee9d8bf0491 100755 (executable)
@@ -55,6 +55,7 @@ class FileDownloader(object):
        password:       Password for authentication purposes.
        usenetrc:       Use netrc for authentication instead.
        quiet:          Do not print messages to stdout.
+       simulate:       Do not download the video files.
        format:         Video format code.
        outtmpl:        Template for output names.
        """
@@ -147,6 +148,10 @@ class FileDownloader(object):
                if not self._params.get('quiet', False):
                        sys.stdout.write('%s%s' % (message, ['\n', ''][skip_eol]))
                        sys.stdout.flush()
+       
+       def to_stderr(self, message):
+               """Print message to stderr."""
+               sys.stderr.write('%s\n' % message)
 
        def download(self, url_list):
                """Download a given list of URLs."""
@@ -162,34 +167,37 @@ class FileDownloader(object):
                                if (len(url_list) > 1 or len(results) > 1) and re.search(r'%\(.+?\)s', self._params['outtmpl']) is None:
                                        sys.exit('ERROR: fixed output name but more than one file to download')
 
+                               if self._params.get('simulate', False):
+                                       continue
+
                                for result in results:
                                        try:
                                                filename = self._params['outtmpl'] % result
                                        except (KeyError), err:
-                                               sys.stderr.write('ERROR: invalid output template: %s\n' % str(err))
+                                               self.to_stderr('ERROR: invalid output template: %s' % str(err))
                                                continue
                                        try:
                                                self.pmkdir(filename)
                                        except (OSError, IOError), err:
-                                               sys.stderr.write('ERROR: unable to create directories: %s\n' % str(err))
+                                               self.to_stderr('ERROR: unable to create directories: %s' % str(err))
                                                continue
                                        try:
                                                outstream = open(filename, 'wb')
                                        except (OSError, IOError), err:
-                                               sys.stderr.write('ERROR: unable to open for writing: %s\n' % str(err))
+                                               self.to_stderr('ERROR: unable to open for writing: %s' % str(err))
                                                continue
                                        try:
                                                self._do_download(outstream, result['url'])
                                                outstream.close()
                                        except (OSError, IOError), err:
-                                               sys.stderr.write('ERROR: unable to write video data: %s\n' % str(err))
+                                               self.to_stderr('ERROR: unable to write video data: %s' % str(err))
                                                continue
                                        except (urllib2.URLError, httplib.HTTPException, socket.error), err:
-                                               sys.stderr.write('ERROR: unable to download video data: %s\n' % str(err))
+                                               self.to_stderr('ERROR: unable to download video data: %s' % str(err))
                                                continue
                                break
                        if not suitable_found:
-                               sys.stderr.write('ERROR: no suitable InfoExtractor: %s\n' % url)
+                               self.to_stderr('ERROR: no suitable InfoExtractor: %s' % url)
        
        def _do_download(self, stream, url):
                request = urllib2.Request(url, None, std_headers)
@@ -435,6 +443,7 @@ if __name__ == '__main__':
                        'username': None,
                        'password': None,
                        'quiet': False,
+                       'simulate': True,
                        'format': None,
                        'outtmpl': '%(id)s.%(ext)s'
                        })