mirror of
https://github.com/l1ving/youtube-dl
synced 2024-11-20 20:42:52 +08:00
Add .to_stderr() to downloaders
This commit is contained in:
parent
b609fd549f
commit
7e5cab6730
16
youtube-dl
16
youtube-dl
@ -149,6 +149,10 @@ class FileDownloader(object):
|
|||||||
sys.stdout.write('%s%s' % (message, ['\n', ''][skip_eol]))
|
sys.stdout.write('%s%s' % (message, ['\n', ''][skip_eol]))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
def to_stderr(self, message):
|
||||||
|
"""Print message to stderr."""
|
||||||
|
sys.stderr.write('%s\n' % message)
|
||||||
|
|
||||||
def download(self, url_list):
|
def download(self, url_list):
|
||||||
"""Download a given list of URLs."""
|
"""Download a given list of URLs."""
|
||||||
for url in url_list:
|
for url in url_list:
|
||||||
@ -170,30 +174,30 @@ class FileDownloader(object):
|
|||||||
try:
|
try:
|
||||||
filename = self._params['outtmpl'] % result
|
filename = self._params['outtmpl'] % result
|
||||||
except (KeyError), err:
|
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
|
continue
|
||||||
try:
|
try:
|
||||||
self.pmkdir(filename)
|
self.pmkdir(filename)
|
||||||
except (OSError, IOError), err:
|
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
|
continue
|
||||||
try:
|
try:
|
||||||
outstream = open(filename, 'wb')
|
outstream = open(filename, 'wb')
|
||||||
except (OSError, IOError), err:
|
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
|
continue
|
||||||
try:
|
try:
|
||||||
self._do_download(outstream, result['url'])
|
self._do_download(outstream, result['url'])
|
||||||
outstream.close()
|
outstream.close()
|
||||||
except (OSError, IOError), err:
|
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
|
continue
|
||||||
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
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
|
continue
|
||||||
break
|
break
|
||||||
if not suitable_found:
|
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):
|
def _do_download(self, stream, url):
|
||||||
request = urllib2.Request(url, None, std_headers)
|
request = urllib2.Request(url, None, std_headers)
|
||||||
|
Loading…
Reference in New Issue
Block a user