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