diff --git a/youtube-dl b/youtube-dl index 320248764e..3986ea0d88 100755 --- a/youtube-dl +++ b/youtube-dl @@ -161,6 +161,7 @@ class FileDownloader(object): def download(self, url_list): """Download a given list of URLs.""" + retcode = 0 if len(url_list) > 1 and self.fixed_template(): sys.exit('ERROR: fixed output name but more than one file to download') @@ -171,7 +172,10 @@ class FileDownloader(object): continue # Suitable InfoExtractor found suitable_found = True - results = [x for x in ie.extract(url) if x is not None] + all_results = ie.extract(url) + results = [x for x in all_results if x is not None] + if len(results) != len(all_results): + retcode = 1 if len(results) > 1 and self.fixed_template(): sys.exit('ERROR: fixed output name but more than one file to download') @@ -192,29 +196,37 @@ class FileDownloader(object): filename = self._params['outtmpl'] % result except (ValueError, KeyError), err: self.to_stderr('ERROR: invalid output template: %s' % str(err)) + retcode = 1 continue try: self.pmkdir(filename) except (OSError, IOError), err: self.to_stderr('ERROR: unable to create directories: %s' % str(err)) + retcode = 1 continue try: outstream = open(filename, 'wb') except (OSError, IOError), err: self.to_stderr('ERROR: unable to open for writing: %s' % str(err)) + retcode = 1 continue try: self._do_download(outstream, result['url']) outstream.close() except (OSError, IOError), err: self.to_stderr('ERROR: unable to write video data: %s' % str(err)) + retcode = 1 continue except (urllib2.URLError, httplib.HTTPException, socket.error), err: self.to_stderr('ERROR: unable to download video data: %s' % str(err)) + retcode = 1 continue break if not suitable_found: self.to_stderr('ERROR: no suitable InfoExtractor: %s' % url) + retcode = 1 + + return retcode def _do_download(self, stream, url): request = urllib2.Request(url, None, std_headers) @@ -359,10 +371,10 @@ class YoutubeIE(InfoExtractor): self.to_stdout('[youtube] Logging in') login_results = urllib2.urlopen(request).read() if re.search(r'(?i)