1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-22 19:58:03 +08:00

Added support for custom user agents.

Added a few simple lines to add support for the flag "--user-agent" to pass a custom string to std_header['User-Agent'].
This commit is contained in:
hdclark 2012-08-22 23:40:35 -07:00
parent 9bb8dc8e42
commit ea46fe2dd4

View File

@ -190,6 +190,8 @@ def parseOpts():
general.add_option('--dump-user-agent', general.add_option('--dump-user-agent',
action='store_true', dest='dump_user_agent', action='store_true', dest='dump_user_agent',
help='display the current browser identification', default=False) help='display the current browser identification', default=False)
general.add_option('--user-agent',
action='store', dest='useragent', help='specify a custom user agent')
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)
@ -368,7 +370,10 @@ def _real_main():
jar.load() jar.load()
except (IOError, OSError), err: except (IOError, OSError), err:
sys.exit(u'ERROR: unable to open cookie file') sys.exit(u'ERROR: unable to open cookie file')
# Set user agent
if opts.useragent is not None:
std_headers['User-Agent'] = opts.useragent
# Dump user agent # Dump user agent
if opts.dump_user_agent: if opts.dump_user_agent:
print std_headers['User-Agent'] print std_headers['User-Agent']