1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-13 05:27:17 +08:00

add extra_http_headers to the request in YoutubeDLHandler.http_request() instead, as recommended by jaimeMF at https://github.com/rg3/youtube-dl/pull/6340

This commit is contained in:
Noah Levitt 2016-04-05 01:15:59 +00:00
parent 5bf28d7864
commit aa094ff1ad
2 changed files with 6 additions and 0 deletions

View File

@ -256,6 +256,7 @@ class YoutubeDL(object):
If it returns None, the video is downloaded. If it returns None, the video is downloaded.
match_filter_func in utils.py is one example for this. match_filter_func in utils.py is one example for this.
no_color: Do not emit color codes in output. no_color: Do not emit color codes in output.
extra_http_headers: Extra http headers to include with every request.
The following options determine which downloader is picked: The following options determine which downloader is picked:
external_downloader: Executable of the external downloader to call. external_downloader: Executable of the external downloader to call.

View File

@ -780,6 +780,11 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
if url != url_escaped: if url != url_escaped:
req = update_Request(req, url=url_escaped) req = update_Request(req, url=url_escaped)
if 'extra_http_headers' in self._params:
for h, v in self._params['extra_http_headers'].items():
if h.capitalize() not in req.headers:
req.add_header(h, v)
for h, v in std_headers.items(): for h, v in std_headers.items():
# Capitalize is needed because of Python bug 2275: http://bugs.python.org/issue2275 # Capitalize is needed because of Python bug 2275: http://bugs.python.org/issue2275
# The dict keys are capitalized because of this bug by urllib # The dict keys are capitalized because of this bug by urllib