mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-28 21:22:13 +00:00
Merge pull request #2553 from anisse/master
Add an option to specify custom HTTP headers
This commit is contained in:
commit
72546c831e
1 changed files with 13 additions and 0 deletions
|
@ -227,6 +227,9 @@ def parseOpts(overrideArguments=None):
|
||||||
general.add_option('--referer',
|
general.add_option('--referer',
|
||||||
dest='referer', help='specify a custom referer, use if the video access is restricted to one domain',
|
dest='referer', help='specify a custom referer, use if the video access is restricted to one domain',
|
||||||
metavar='REF', default=None)
|
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',
|
general.add_option('--list-extractors',
|
||||||
action='store_true', dest='list_extractors',
|
action='store_true', dest='list_extractors',
|
||||||
help='List all supported extractors and the URLs they would handle', default=False)
|
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:
|
if opts.referer is not None:
|
||||||
std_headers['Referer'] = opts.referer
|
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
|
# Dump user agent
|
||||||
if opts.dump_user_agent:
|
if opts.dump_user_agent:
|
||||||
compat_print(std_headers['User-Agent'])
|
compat_print(std_headers['User-Agent'])
|
||||||
|
|
Loading…
Reference in a new issue