- all_results = ie.extract(url)
- results = [x for x in all_results if x is not None]
- if len(results) != len(all_results):
- retcode = self.trouble()
-
- if len(results) > 1 and self.fixed_template():
- raise SameFileError(self._params['outtmpl'])
-
- for result in results:
- # Forced printings
- if self._params.get('forcetitle', False):
- print result['title']
- if self._params.get('forceurl', False):
- print result['url']
-
- # Do nothing else if in simulate mode
- if self._params.get('simulate', False):
- continue
-
- try:
- filename = self._params['outtmpl'] % result
- self.report_destination(filename)
- except (ValueError, KeyError), err:
- retcode = self.trouble('ERROR: invalid output template or system charset: %s' % str(err))
- continue
- try:
- self.pmkdir(filename)
- except (OSError, IOError), err:
- retcode = self.trouble('ERROR: unable to create directories: %s' % str(err))
- continue
- try:
- outstream = open(filename, 'wb')
- except (OSError, IOError), err:
- retcode = self.trouble('ERROR: unable to open for writing: %s' % str(err))
- continue
- try:
- self._do_download(outstream, result['url'])
- outstream.close()
- except (OSError, IOError), err:
- retcode = self.trouble('ERROR: unable to write video data: %s' % str(err))
- continue
- except (urllib2.URLError, httplib.HTTPException, socket.error), err:
- retcode = self.trouble('ERROR: unable to download video data: %s' % str(err))
- continue
- try:
- self.post_process(filename, result)
- except (PostProcessingError), err:
- retcode = self.trouble('ERROR: postprocessing: %s' % str(err))
- continue