Merge branch 'daum' of https://github.com/remitamine/youtube-dl into remitamine-daum
[youtube-dl] / youtube_dl / utils.py
index 6d31197606bf67bc2686b24a956a21a2536abd73..0ed6c45c8090e7d328ec4e09d12875adc768c0f9 100644 (file)
@@ -773,11 +773,13 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
                     raise original_ioerror
             resp = self.addinfourl_wrapper(uncompressed, old_resp.headers, old_resp.url, old_resp.code)
             resp.msg = old_resp.msg
+            del resp.headers['Content-encoding']
         # deflate
         if resp.headers.get('Content-encoding', '') == 'deflate':
             gz = io.BytesIO(self.deflate(resp.read()))
             resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code)
             resp.msg = old_resp.msg
+            del resp.headers['Content-encoding']
         # Percent-encode redirect URL of Location HTTP header to satisfy RFC 3986 (see
         # https://github.com/rg3/youtube-dl/issues/6457).
         if 300 <= resp.code < 400:
@@ -1712,6 +1714,10 @@ def encode_dict(d, encoding='utf-8'):
     return dict((encode(k), encode(v)) for k, v in d.items())
 
 
+def encode_compat_str(string, encoding=preferredencoding(), errors='strict'):
+    return string if isinstance(string, compat_str) else compat_str(string, encoding, errors)
+
+
 US_RATINGS = {
     'G': 0,
     'PG': 10,
@@ -1806,7 +1812,7 @@ def args_to_str(args):
     return ' '.join(shlex_quote(a) for a in args)
 
 
-def error_to_str(err):
+def error_to_compat_str(err):
     err_str = str(err)
     # On python 2 error byte string must be decoded with proper
     # encoding rather than ascii