diff --git a/youtube-dl b/youtube-dl index e6f05c173..71a58a1d8 100755 Binary files a/youtube-dl and b/youtube-dl differ diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py index e3131bbe6..a00a2b3b2 100644 --- a/youtube_dl/FileDownloader.py +++ b/youtube_dl/FileDownloader.py @@ -609,6 +609,59 @@ class FileDownloader(object): self.trouble(u'\nERROR: rtmpdump exited with code %d' % retval) return False + # Keep a copy of the main cookiejar to pass to external downloaders + # + # This seems like a stupid way of copying a cookie, but if Alex + # Martelli says so... + # http://stackoverflow.com/a/1023235/962311 + def _keep_cookie_jar(self): + from youtube_dl import jar + import tempfile + + new_filedesc, new_filename = tempfile.mkstemp() + new_jar = compat_cookiejar.MozillaCookieJar(new_filename) + + for c in jar: + new_jar.set_cookie(c) + + new_jar.save(new_filename) + + return new_filename + + def _download_with_aria2c(self, filename, url): + self.report_destination(filename) + + # Check for aria2c first + try: + subprocess.call(['aria2c', '-h'], + stdout=(file(os.path.devnull, 'w')), + stderr=subprocess.STDOUT) + except (OSError, IOError): + self.trouble(u'ERROR: external program requested, but "aria2c" could not be run') + return False + + tmp_jar_name = self._keep_cookie_jar() + + basic_args = ['aria2c', '-c'] + basic_args += ['--min-split-size', '1M'] + basic_args += ['--max-connection-per-server', '4'] + basic_args += ['--user-agent', std_headers['User-Agent']] + basic_args += ['--load-cookies=' + tmp_jar_name ] + basic_args += ['-o', filename, url] + + retval = subprocess.call(basic_args) + + # The cookie jar is not necessary anymore + os.unlink(tmp_jar_name) + + + if retval == 0: + self.to_screen(u'\r[aria2c] %s bytes' % os.path.getsize(filename)) + return True + else: + self.trouble(u'\nERROR: aria2c exited with code %d' % retval) + return False + def _do_download(self, filename, info_dict): url = info_dict['url'] @@ -630,6 +683,8 @@ class FileDownloader(object): tmpfilename = self.temp_name(filename) stream = None + return self._download_with_aria2c(filename, url) + # Do not include the Accept-Encoding header headers = {'Youtubedl-no-compression': 'True'} if 'user_agent' in info_dict: diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index c80593686..86be14b1e 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -283,6 +283,7 @@ jar = None def _real_main(): parser, opts, args = parseOpts() + global jar # Open appropriate CookieJar if opts.cookiefile is None: jar = compat_cookiejar.CookieJar()