summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2014-03-24 10:42:58 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2014-03-24 10:42:58 +0100
commit72546c831e460307570ae292053c8395e2bbf0ef (patch)
treef4426ffa877c85564acf56c367dd4b4d771b4df4
parentd26db9269daf35ab1ab0cfe35bfffd49af834343 (diff)
parent410afb2003f48df92720da7d4ea37560692138a4 (diff)
downloadyoutube-dl-72546c831e460307570ae292053c8395e2bbf0ef.tar.gz
youtube-dl-72546c831e460307570ae292053c8395e2bbf0ef.tar.xz
youtube-dl-72546c831e460307570ae292053c8395e2bbf0ef.zip
Merge pull request #2553 from anisse/master
Add an option to specify custom HTTP headers
-rw-r--r--youtube_dl/__init__.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
index a4cbdb0bd..056e94457 100644
--- a/youtube_dl/__init__.py
+++ b/youtube_dl/__init__.py
@@ -227,6 +227,9 @@ def parseOpts(overrideArguments=None):
     general.add_option('--referer',
             dest='referer', help='specify a custom referer, use if the video access is restricted to one domain',
             metavar='REF', default=None)
+    general.add_option('--add-header',
+            dest='headers', help='specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times', action="append",
+            metavar='FIELD:VALUE')
     general.add_option('--list-extractors',
             action='store_true', dest='list_extractors',
             help='List all supported extractors and the URLs they would handle', default=False)
@@ -556,6 +559,16 @@ def _real_main(argv=None):
     if opts.referer is not None:
         std_headers['Referer'] = opts.referer
 
+    # Custom HTTP headers
+    if opts.headers is not None:
+        for h in opts.headers:
+            if h.find(':', 1) < 0:
+                parser.error(u'wrong header formatting, it should be key:value, not "%s"'%h)
+            key, value = h.split(':', 2)
+            if opts.verbose:
+                write_string(u'[debug] Adding header from command line option %s:%s\n'%(key, value))
+            std_headers[key] = value
+
     # Dump user agent
     if opts.dump_user_agent:
         compat_print(std_headers['User-Agent'])