Merge pull request #405 from hdclark/master
[youtube-dl] / youtube_dl / __init__.py
index 5e500d5e0243052eeb762f9cdf15de3c3782ddae..180a0707d6df31860143e71bbb612181a3066549 100644 (file)
@@ -19,7 +19,7 @@ __authors__  = (
        )
 
 __license__ = 'Public Domain'
-__version__ = '2012.02.27'
+__version__ = '2012.09.27'
 
 UPDATE_URL = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl'
 UPDATE_URL_VERSION = 'https://raw.github.com/rg3/youtube-dl/master/LATEST_VERSION'
@@ -60,13 +60,17 @@ def updateSelf(downloader, filename):
        urlv.close()
 
        if hasattr(sys, "frozen"): #py2exe
-               directory = os.path.dirname(filename)
                exe = os.path.abspath(filename)
+               directory = os.path.dirname(exe)
                if not os.access(directory, os.W_OK):
                        sys.exit('ERROR: no write permissions on %s' % directory)
                        
                try:
-                       urllib.urlretrieve(UPDATE_URL_EXE, exe + '.new')
+                       urlh = urllib2.urlopen(UPDATE_URL_EXE)
+                       newcontent = urlh.read()
+                       urlh.close()
+                       with open(exe + '.new', 'wb') as outf:
+                               outf.write(newcontent)
                except (IOError, OSError), err:
                        sys.exit('ERROR: unable to download latest version')
                        
@@ -75,6 +79,7 @@ def updateSelf(downloader, filename):
                        b = open(bat, 'w')
                        
                        print >> b, """
+echo Updating youtube-dl...
 ping 127.0.0.1 -n 5 -w 1000 > NUL
 move /Y "%s.new" "%s"
 del "%s"
@@ -95,11 +100,8 @@ del "%s"
                        sys.exit('ERROR: unable to download latest version')
 
                try:
-                       outf = open(filename, 'wb')
-                       try:
+                       with open(filename, 'wb') as outf:
                                outf.write(newcontent)
-                       finally:
-                               outf.close()
                except (IOError, OSError), err:
                        sys.exit('ERROR: unable to overwrite current version')
 
@@ -188,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)
@@ -291,11 +295,11 @@ def parseOpts():
 
 
        postproc.add_option('--extract-audio', action='store_true', dest='extractaudio', default=False,
-                       help='convert video files to audio-only files (requires ffmpeg and ffprobe)')
+                       help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
        postproc.add_option('--audio-format', metavar='FORMAT', dest='audioformat', default='best',
                        help='"best", "aac", "vorbis", "mp3", "m4a", or "wav"; best by default')
        postproc.add_option('--audio-quality', metavar='QUALITY', dest='audioquality', default='128K',
-                       help='ffmpeg audio bitrate specification, 128k by default')
+                       help='ffmpeg/avconv audio bitrate specification, 128k by default')
        postproc.add_option('-k', '--keep-video', action='store_true', dest='keepvideo', default=False,
                        help='keeps the video file on disk after the post-processing; the video is erased by default')
 
@@ -336,6 +340,7 @@ def gen_extractors():
                YahooSearchIE(),
                DepositFilesIE(),
                FacebookIE(),
+               BlipTVUserIE(),
                BlipTVIE(),
                VimeoIE(),
                MyVideoIE(),
@@ -348,6 +353,8 @@ def gen_extractors():
                MixcloudIE(),
                StanfordOpenClassroomIE(),
                MTVIE(),
+               YoukuIE(),
+               XNXXIE(),
 
                GenericIE()
        ]
@@ -365,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']
@@ -394,9 +404,6 @@ def _real_main():
        urllib2.install_opener(opener)
        socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words)
 
-       if opts.verbose:
-               print(u'[debug] Proxy map: ' + str(proxy_handler.proxies))
-
        extractors = gen_extractors()
 
        if opts.list_extractors:
@@ -494,6 +501,10 @@ def _real_main():
                'prefer_free_formats': opts.prefer_free_formats,
                'verbose': opts.verbose,
                })
+
+       if opts.verbose:
+               fd.to_screen(u'[debug] Proxy map: ' + str(proxy_handler.proxies))
+
        for extractor in extractors:
                fd.add_info_extractor(extractor)