A feature-rich command-line audio/video downloader
Move the downloader return code to a class member
Ricardo Garcia9bf386d74bdc
diff --git a/youtube-dl b/youtube-dlindex bc7e3b5fe9..5c3746b541 100755--- a/youtube-dl+++ b/youtube-dl@@ -95,11 +95,13 @@ class FileDownloader(object):params = None_ies = []_pps = []+ _download_retcode = Nonedef __init__(self, params):"""Create a FileDownloader object with the given options."""self._ies = []self._pps = []+ self._download_retcode = 0self.params = params@staticmethod@@ -203,15 +205,13 @@ class FileDownloader(object):Depending on if the downloader has been configured to ignoredownload errors or not, this method may throw an exception or- not when errors are found, after printing the message. If it- doesn't raise, it returns an error code suitable to be returned- later as a program exit code to indicate error.+ not when errors are found, after printing the message."""if message is not None:self.to_stderr(message)if not self.params.get('ignoreerrors', False):raise DownloadError(message)- return 1+ self._download_retcode = 1def slow_down(self, start_time, byte_counter):"""Sleep if the download speed is over the rate limit."""@@ -249,41 +249,45 @@ class FileDownloader(object):# Do nothing else if in simulate modeif self.params.get('simulate', False):- return 0+ returntry:filename = self.params['outtmpl'] % info_dictself.report_destination(filename)except (ValueError, KeyError), err:- return self.trouble('ERROR: invalid output template or system charset: %s' % str(err))+ self.trouble('ERROR: invalid output template or system charset: %s' % str(err))if self.params['nooverwrites'] and os.path.exists(filename):self.to_stderr('WARNING: file exists: %s; skipping' % filename)- return 0+ returntry:self.pmkdir(filename)except (OSError, IOError), err:- return self.trouble('ERROR: unable to create directories: %s' % str(err))+ self.trouble('ERROR: unable to create directories: %s' % str(err))+ returntry:outstream = open(filename, 'wb')except (OSError, IOError), err:- return self.trouble('ERROR: unable to open for writing: %s' % str(err))+ self.trouble('ERROR: unable to open for writing: %s' % str(err))+ returntry:self._do_download(outstream, info_dict['url'])outstream.close()except (OSError, IOError), err:- return self.trouble('ERROR: unable to write video data: %s' % str(err))+ self.trouble('ERROR: unable to write video data: %s' % str(err))+ returnexcept (urllib2.URLError, httplib.HTTPException, socket.error), err:- return self.trouble('ERROR: unable to download video data: %s' % str(err))+ self.trouble('ERROR: unable to download video data: %s' % str(err))+ returntry:self.post_process(filename, info_dict)except (PostProcessingError), err:- return self.trouble('ERROR: postprocessing: %s' % str(err))+ self.trouble('ERROR: postprocessing: %s' % str(err))+ return- return 0+ returndef download(self, url_list):"""Download a given list of URLs."""- retcode = 0if len(url_list) > 1 and self.fixed_template():raise SameFileError(self.params['outtmpl'])@@ -303,7 +307,7 @@ class FileDownloader(object):# See if there were problems extracting any informationif len(results) != len(all_results):- retcode = self.trouble()+ self.trouble()# Two results could go to the same fileif len(results) > 1 and self.fixed_template():@@ -311,19 +315,15 @@ class FileDownloader(object):# Process each resultfor result in results:- result = self.process_info(result)-- # Do not overwrite an error code with a success code- if result != 0:- retcode = result+ self.process_info(result)# Suitable InfoExtractor had been found; go to next URLbreakif not suitable_found:- retcode = self.trouble('ERROR: no suitable InfoExtractor: %s' % url)+ self.trouble('ERROR: no suitable InfoExtractor: %s' % url)- return retcode+ return self._download_retcodedef post_process(self, filename, ie_info):"""Run the postprocessing chain on the given file."""