]> git.bitcoin.ninja Git - youtube-dl/commitdiff
Merge branch 'opener-to-ydl'
authorPhilipp Hagemeister <phihag@phihag.de>
Mon, 25 Nov 2013 02:30:37 +0000 (03:30 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Mon, 25 Nov 2013 02:30:37 +0000 (03:30 +0100)
1  2 
youtube_dl/YoutubeDL.py
youtube_dl/extractor/common.py
youtube_dl/utils.py

index a896d9e637094755f3ba521d26758b145f518aaa,87eb1a0b37fd5342b9a50d55109a2efe29a8c2fb..30ba94666a642c45bfc03af75eb09019c04ae9ad
@@@ -30,10 -33,11 +33,12 @@@ from .utils import 
      DownloadError,
      encodeFilename,
      ExtractorError,
 +    format_bytes,
      locked_file,
+     make_HTTPS_handler,
      MaxDownloadsReached,
      PostProcessingError,
+     platform_name,
      preferredencoding,
      SameFileError,
      sanitize_filename,
@@@ -911,6 -920,76 +926,76 @@@ class YoutubeDL(object)
  
          header_line = line({
              'format_id': u'format code', 'ext': u'extension',
 -            '_resolution': u'resolution', 'format_note': u'note'})
 +            '_resolution': u'resolution', 'format_note': u'note'}, idlen=idlen)
          self.to_screen(u'[info] Available formats for %s:\n%s\n%s' %
                         (info_dict['id'], header_line, u"\n".join(formats_s)))
+     def urlopen(self, req):
+         """ Start an HTTP download """
+         return self._opener.open(req)
+     def print_debug_header(self):
+         if not self.params.get('verbose'):
+             return
+         write_string(u'[debug] youtube-dl version ' + __version__ + u'\n')
+         try:
+             sp = subprocess.Popen(
+                 ['git', 'rev-parse', '--short', 'HEAD'],
+                 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                 cwd=os.path.dirname(os.path.abspath(__file__)))
+             out, err = sp.communicate()
+             out = out.decode().strip()
+             if re.match('[0-9a-f]+', out):
+                 write_string(u'[debug] Git HEAD: ' + out + u'\n')
+         except:
+             try:
+                 sys.exc_clear()
+             except:
+                 pass
+         write_string(u'[debug] Python version %s - %s' %
+                      (platform.python_version(), platform_name()) + u'\n')
+         proxy_map = {}
+         for handler in self._opener.handlers:
+             if hasattr(handler, 'proxies'):
+                 proxy_map.update(handler.proxies)
+         write_string(u'[debug] Proxy map: ' + compat_str(proxy_map) + u'\n')
+     def _setup_opener(self, timeout=300):
+         opts_cookiefile = self.params.get('cookiefile')
+         opts_proxy = self.params.get('proxy')
+         if opts_cookiefile is None:
+             self.cookiejar = compat_cookiejar.CookieJar()
+         else:
+             self.cookiejar = compat_cookiejar.MozillaCookieJar(
+                 opts_cookiefile)
+             if os.access(opts_cookiefile, os.R_OK):
+                 self.cookiejar.load()
+         cookie_processor = compat_urllib_request.HTTPCookieProcessor(
+             self.cookiejar)
+         if opts_proxy is not None:
+             if opts_proxy == '':
+                 proxies = {}
+             else:
+                 proxies = {'http': opts_proxy, 'https': opts_proxy}
+         else:
+             proxies = compat_urllib_request.getproxies()
+             # Set HTTPS proxy to HTTP one if given (https://github.com/rg3/youtube-dl/issues/805)
+             if 'http' in proxies and 'https' not in proxies:
+                 proxies['https'] = proxies['http']
+         proxy_handler = compat_urllib_request.ProxyHandler(proxies)
+         https_handler = make_HTTPS_handler(
+             self.params.get('nocheckcertificate', False))
+         opener = compat_urllib_request.build_opener(
+             https_handler, proxy_handler, cookie_processor, YoutubeDLHandler())
+         # Delete the default user-agent header, which would otherwise apply in
+         # cases where our custom HTTP handler doesn't come into play
+         # (See https://github.com/rg3/youtube-dl/issues/1309 for details)
+         opener.addheaders = []
+         self._opener = opener
+         # TODO remove this global modification
+         compat_urllib_request.install_opener(opener)
+         socket.setdefaulttimeout(timeout)
Simple merge
Simple merge