aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>2008-07-22 00:07:07 +0200
committerRicardo Garcia <devnull@localhost>2008-07-22 00:07:07 +0200
commit7e5cab673024e93a706afa64f9fc38e25e8df085 (patch)
treec5871d8088d5b61df3d7c47e77aa9374ba73b905
parentb609fd549ffd7e3f8450f784eb34e84249d710c7 (diff)
Add .to_stderr() to downloaders
-rwxr-xr-xyoutube-dl16
1 files changed, 10 insertions, 6 deletions
diff --git a/youtube-dl b/youtube-dl
index 7323ad4f2..1c4a05471 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -148,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."""
@@ -170,30 +174,30 @@ class FileDownloader(object):
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)