]> gitweb @ CieloNegro.org - youtube-dl.git/blobdiff - youtube-dl
Add que -w or --no-overwrites option
[youtube-dl.git] / youtube-dl
index 29afd930f0782ccfc01b74150e9aefbe885307c7..de6c7a1d1909da79e9b30877b6729946df0f65fe 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
@@ -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:
@@ -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()
@@ -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)