|
|
@ -1308,25 +1308,12 @@ def _create_http_connection(ydl_handler, http_class, is_https, *args, **kwargs):
|
|
|
|
return hc
|
|
|
|
return hc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_youtubedl_headers(headers):
|
|
|
|
|
|
|
|
filtered_headers = headers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'Youtubedl-no-compression' in filtered_headers:
|
|
|
|
|
|
|
|
filtered_headers = {k: v for k, v in filtered_headers.items() if k.lower() != 'accept-encoding'}
|
|
|
|
|
|
|
|
del filtered_headers['Youtubedl-no-compression']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return filtered_headers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class YoutubeDLHandler(urllib.request.HTTPHandler):
|
|
|
|
class YoutubeDLHandler(urllib.request.HTTPHandler):
|
|
|
|
"""Handler for HTTP requests and responses.
|
|
|
|
"""Handler for HTTP requests and responses.
|
|
|
|
|
|
|
|
|
|
|
|
This class, when installed with an OpenerDirector, automatically adds
|
|
|
|
This class, when installed with an OpenerDirector, automatically adds
|
|
|
|
the standard headers to every HTTP request and handles gzipped and
|
|
|
|
the standard headers to every HTTP request and handles gzipped, deflated and
|
|
|
|
deflated responses from web servers. If compression is to be avoided in
|
|
|
|
brotli responses from web servers.
|
|
|
|
a particular request, the original request in the program code only has
|
|
|
|
|
|
|
|
to include the HTTP header "Youtubedl-no-compression", which will be
|
|
|
|
|
|
|
|
removed before making the real request.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Part of this code was copied from:
|
|
|
|
Part of this code was copied from:
|
|
|
|
|
|
|
|
|
|
|
@ -1389,11 +1376,13 @@ class YoutubeDLHandler(urllib.request.HTTPHandler):
|
|
|
|
if h.capitalize() not in req.headers:
|
|
|
|
if h.capitalize() not in req.headers:
|
|
|
|
req.add_header(h, v)
|
|
|
|
req.add_header(h, v)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'Youtubedl-no-compression' in req.headers: # deprecated
|
|
|
|
|
|
|
|
req.headers.pop('Youtubedl-no-compression', None)
|
|
|
|
|
|
|
|
req.add_header('Accept-encoding', 'identity')
|
|
|
|
|
|
|
|
|
|
|
|
if 'Accept-encoding' not in req.headers:
|
|
|
|
if 'Accept-encoding' not in req.headers:
|
|
|
|
req.add_header('Accept-encoding', ', '.join(SUPPORTED_ENCODINGS))
|
|
|
|
req.add_header('Accept-encoding', ', '.join(SUPPORTED_ENCODINGS))
|
|
|
|
|
|
|
|
|
|
|
|
req.headers = handle_youtubedl_headers(req.headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return super().do_request_(req)
|
|
|
|
return super().do_request_(req)
|
|
|
|
|
|
|
|
|
|
|
|
def http_response(self, req, resp):
|
|
|
|
def http_response(self, req, resp):
|
|
|
|