]> gitweb @ CieloNegro.org - youtube-dl.git/blobdiff - youtube-dl
Bump version number
[youtube-dl.git] / youtube-dl
index 29afd930f0782ccfc01b74150e9aefbe885307c7..192f9b21fa711ca99565cbb270ee60de3c1a5cc6 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 # Author: Ricardo Garcia Gonzalez
+# Author: Danny Colligan
 # License: Public domain code
 import htmlentitydefs
 import httplib
@@ -88,6 +89,7 @@ class FileDownloader(object):
        outtmpl:        Template for output names.
        ignoreerrors:   Do not stop on download errors.
        ratelimit:      Download speed limit, in bytes/sec.
+       nooverwrites:   Prevent overwriting files.
        """
 
        _params = None
@@ -142,7 +144,7 @@ class FileDownloader(object):
                        return '--:--'
                return '%02d:%02d' % (eta_mins, eta_secs)
 
-       @staticmethod
+       @staticmethod
        def calc_speed(start, now, bytes):
                dif = now - start
                if bytes == 0 or dif < 0.001: # One millisecond
@@ -285,6 +287,9 @@ class FileDownloader(object):
                                        except (ValueError, KeyError), err:
                                                retcode = self.trouble('ERROR: invalid output template or system charset: %s' % str(err))
                                                continue
+                                       if self._params['nooverwrites'] and os.path.exists(filename):
+                                               self.to_stderr('WARNING: file exists: %s; skipping' % filename)
+                                               continue
                                        try:
                                                self.pmkdir(filename)
                                        except (OSError, IOError), err:
@@ -488,12 +493,8 @@ class YoutubeIE(InfoExtractor):
                                self.to_stderr(u'WARNING: parsing .netrc: %s' % str(err))
                                return
 
-               # No authentication to be performed
-               if username is None:
-                       return
-
                # Set language
-               request = urllib2.Request(self._LOGIN_URL, None, std_headers)
+               request = urllib2.Request(self._LANG_URL, None, std_headers)
                try:
                        self.report_lang()
                        urllib2.urlopen(request).read()
@@ -501,6 +502,10 @@ class YoutubeIE(InfoExtractor):
                        self.to_stderr(u'WARNING: unable to set language: %s' % str(err))
                        return
 
+               # No authentication to be performed
+               if username is None:
+                       return
+
                # Log in
                login_form = {
                                'current_form': 'loginForm',
@@ -776,7 +781,7 @@ class YoutubeSearchIE(InfoExtractor):
 
                while True:
                        self.report_download_page(query, pagenum)
-                       result_url = self._TEMPLATE_URL % (urllib.quote(query.replace(' ', '+')), pagenum)
+                       result_url = self._TEMPLATE_URL % (urllib.quote_plus(query), pagenum)
                        request = urllib2.Request(result_url, None, std_headers)
                        try:
                                page = urllib2.urlopen(request).read()
@@ -936,7 +941,7 @@ if __name__ == '__main__':
                # Parse command line
                parser = optparse.OptionParser(
                                usage='Usage: %prog [options] url...',
-                               version='2009.01.31',
+                               version='2009.03.03',
                                conflict_handler='resolve',
                                )
                parser.add_option('-h', '--help',
@@ -975,6 +980,8 @@ if __name__ == '__main__':
                                dest='ratelimit', metavar='L', help='download rate limit (e.g. 50k or 44.6m)')
                parser.add_option('-a', '--batch-file',
                                dest='batchfile', metavar='F', help='file containing URLs to download')
+               parser.add_option('-w', '--no-overwrites',
+                               action='store_true', dest='nooverwrites', help='do not overwrite files', default=False)
                (opts, args) = parser.parse_args()
 
                # Batch file verification
@@ -1030,6 +1037,7 @@ if __name__ == '__main__':
                                or u'%(id)s.%(ext)s'),
                        'ignoreerrors': opts.ignoreerrors,
                        'ratelimit': opts.ratelimit,
+                       'nooverwrites': opts.nooverwrites,
                        })
                fd.add_info_extractor(youtube_search_ie)
                fd.add_info_extractor(youtube_pl_ie)