verbose flag, and output proxies if it is set
[youtube-dl.git] / youtube_dl / __init__.py
index 0f9eecc..4c9c237 100755 (executable)
@@ -18,7 +18,7 @@ __authors__  = (
        )
 
 __license__ = 'Public Domain'
-__version__ = '2012.01.05'
+__version__ = '2012.01.08b'
 
 UPDATE_URL = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl'
 
@@ -305,7 +305,14 @@ def _encodeFilename(s):
        """
 
        assert type(s) == type(u'')
-       return s.encode(sys.getfilesystemencoding(), 'ignore')
+
+       if sys.platform == 'win32' and sys.getwindowsversion().major >= 5:
+               # Pass u'' directly to use Unicode APIs on Windows 2000 and up
+               # (Detecting Windows NT 4 is tricky because 'major >= 4' would
+               # match Windows 9x series as well. Besides, NT 4 is obsolete.)
+               return s
+       else:
+               return s.encode(sys.getfilesystemencoding(), 'ignore')
 
 class DownloadError(Exception):
        """Download Error exception.
@@ -2652,7 +2659,7 @@ class YoutubeUserIE(InfoExtractor):
                else:
                        video_ids = video_ids[playliststart:playlistend]
 
-               self._downloader.to_screen("[youtube] user %s: Collected %d video ids (downloading %d of them)" %
+               self._downloader.to_screen(u"[youtube] user %s: Collected %d video ids (downloading %d of them)" %
                                (username, all_ids_count, len(video_ids)))
 
                for video_id in video_ids:
@@ -4170,7 +4177,7 @@ def updateSelf(downloader, filename):
        if not os.access(filename, os.W_OK):
                sys.exit('ERROR: no write permissions on %s' % filename)
 
-       downloader.to_screen('Updating to latest version...')
+       downloader.to_screen(u'Updating to latest version...')
 
        try:
                try:
@@ -4179,7 +4186,7 @@ def updateSelf(downloader, filename):
                        
                        vmatch = re.search("__version__ = '([^']+)'", newcontent)
                        if vmatch is not None and vmatch.group(1) == __version__:
-                               downloader.to_screen('youtube-dl is up-to-date (' + __version__ + ')')
+                               downloader.to_screen(u'youtube-dl is up-to-date (' + __version__ + ')')
                                return
                finally:
                        urlh.close()
@@ -4195,7 +4202,7 @@ def updateSelf(downloader, filename):
        except (IOError, OSError), err:
                sys.exit('ERROR: unable to overwrite current version')
 
-       downloader.to_screen('Updated youtube-dl. Restart youtube-dl to use the new version.')
+       downloader.to_screen(u'Updated youtube-dl. Restart youtube-dl to use the new version.')
 
 def parseOpts():
        # Deferred imports
@@ -4344,6 +4351,8 @@ def parseOpts():
        verbosity.add_option('--console-title',
                        action='store_true', dest='consoletitle',
                        help='display progress in console titlebar', default=False)
+       verbosity.add_option('-v', '--verbose',
+                       action='store_true', dest='verbose', help='print various debugging information', default=False)
 
 
        filesystem.add_option('-t', '--title',
@@ -4480,10 +4489,14 @@ def _real_main():
 
        # General configuration
        cookie_processor = urllib2.HTTPCookieProcessor(jar)
-       opener = urllib2.build_opener(urllib2.ProxyHandler(), cookie_processor, YoutubeDLHandler())
+       proxy_handler = urllib2.ProxyHandler()
+       opener = urllib2.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
        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: