From aa094ff1ad7832323a634a53660faa4c73d39577 Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Tue, 5 Apr 2016 01:15:59 +0000 Subject: [PATCH] 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 --- youtube_dl/YoutubeDL.py | 1 + youtube_dl/utils.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index d7aa951ff..a57d7e606 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -256,6 +256,7 @@ class YoutubeDL(object): If it returns None, the video is downloaded. match_filter_func in utils.py is one example for this. 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: external_downloader: Executable of the external downloader to call. diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 8e53962c9..f8ff0e0f2 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -780,6 +780,11 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler): if 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(): # Capitalize is needed because of Python bug 2275: http://bugs.python.org/issue2275 # The dict keys are capitalized because of this bug by urllib