Merge pull request #405 from hdclark/master
authorPhilipp Hagemeister <phihag@phihag.de>
Thu, 27 Sep 2012 17:56:25 +0000 (10:56 -0700)
committerPhilipp Hagemeister <phihag@phihag.de>
Thu, 27 Sep 2012 17:56:25 +0000 (10:56 -0700)
Support for custom user agent

youtube_dl/__init__.py

index 5ed453bf732650f4169bc189ca8c7a1aa291eb7d..180a0707d6df31860143e71bbb612181a3066549 100644 (file)
@@ -190,6 +190,8 @@ def parseOpts():
        general.add_option('--dump-user-agent',
                        action='store_true', dest='dump_user_agent',
                        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',
                        action='store_true', dest='list_extractors',
                        help='List all supported extractors and the URLs they would handle', default=False)
@@ -370,7 +372,10 @@ def _real_main():
                                jar.load()
                except (IOError, OSError), err:
                        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
        if opts.dump_user_agent:
                print std_headers['User-Agent']