]> git.bitcoin.ninja Git - youtube-dl/blobdiff - youtube_dl/utils.py
[utils] Prevent override of custom headers.
[youtube-dl] / youtube_dl / utils.py
index cc5f510f40fff66ce374f2586aae43686a240b7d..daf94abd1d541d77e8b74f0f17e6fde780b054e8 100644 (file)
@@ -287,6 +287,8 @@ def sanitize_filename(s, restricted=False, is_id=False):
             return '_'
         return char
 
+    # Handle timestamps
+    s = re.sub(r'[0-9]+(?::[0-9]+)+', lambda m: m.group(0).replace(':', '_'), s)
     result = ''.join(map(replace_insane, s))
     if not is_id:
         while '__' in result:
@@ -545,7 +547,7 @@ class ContentTooShortError(Exception):
         self.expected = expected
 
 
-def _create_http_connection(ydl_handler, http_class, is_https=False, *args, **kwargs):
+def _create_http_connection(ydl_handler, http_class, is_https, *args, **kwargs):
     hc = http_class(*args, **kwargs)
     source_address = ydl_handler._params.get('source_address')
     if source_address is not None:
@@ -589,7 +591,7 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
 
     def http_open(self, req):
         return self.do_open(functools.partial(
-            _create_http_connection, self, compat_http_client.HTTPConnection),
+            _create_http_connection, self, compat_http_client.HTTPConnection, False),
             req)
 
     @staticmethod
@@ -609,7 +611,9 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
 
     def http_request(self, req):
         for h, v in std_headers.items():
-            if h not in req.headers:
+            # Capitalize is needed because of Python bug 2275: http://bugs.python.org/issue2275
+            # The dict keys are capitalized because of this bug by urllib
+            if h.capitalize() not in req.headers:
                 req.add_header(h, v)
         if 'Youtubedl-no-compression' in req.headers:
             if 'Accept-encoding' in req.headers:
@@ -1267,7 +1271,7 @@ def float_or_none(v, scale=1, invscale=1, default=None):
 
 
 def parse_duration(s):
-    if s is None:
+    if not isinstance(s, basestring if sys.version_info < (3, 0) else compat_str):
         return None
 
     s = s.strip()