|
|
@ -2,6 +2,7 @@
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import gzip
|
|
|
|
import gzip
|
|
|
|
|
|
|
|
import io
|
|
|
|
import locale
|
|
|
|
import locale
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import re
|
|
|
@ -10,11 +11,6 @@ import zlib
|
|
|
|
import email.utils
|
|
|
|
import email.utils
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
import cStringIO as StringIO
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
import StringIO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
import urllib.request as compat_urllib_request
|
|
|
|
import urllib.request as compat_urllib_request
|
|
|
|
except ImportError: # Python 2
|
|
|
|
except ImportError: # Python 2
|
|
|
@ -400,12 +396,12 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
|
|
|
|
old_resp = resp
|
|
|
|
old_resp = resp
|
|
|
|
# gzip
|
|
|
|
# gzip
|
|
|
|
if resp.headers.get('Content-encoding', '') == 'gzip':
|
|
|
|
if resp.headers.get('Content-encoding', '') == 'gzip':
|
|
|
|
gz = gzip.GzipFile(fileobj=StringIO.StringIO(resp.read()), mode='r')
|
|
|
|
gz = gzip.GzipFile(fileobj=io.BytesIO(resp.read()), mode='r')
|
|
|
|
resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code)
|
|
|
|
resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code)
|
|
|
|
resp.msg = old_resp.msg
|
|
|
|
resp.msg = old_resp.msg
|
|
|
|
# deflate
|
|
|
|
# deflate
|
|
|
|
if resp.headers.get('Content-encoding', '') == 'deflate':
|
|
|
|
if resp.headers.get('Content-encoding', '') == 'deflate':
|
|
|
|
gz = StringIO.StringIO(self.deflate(resp.read()))
|
|
|
|
gz = io.BytesIO(self.deflate(resp.read()))
|
|
|
|
resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code)
|
|
|
|
resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code)
|
|
|
|
resp.msg = old_resp.msg
|
|
|
|
resp.msg = old_resp.msg
|
|
|
|
return resp
|
|
|
|
return resp
|
|
|
|