Add que -w or --no-overwrites option

This commit is contained in:
Ricardo Garcia 2009-02-04 21:38:31 +01:00
parent 64a6f26c5d
commit 0beeff4b3e

View file

@ -89,6 +89,7 @@ class FileDownloader(object):
outtmpl: Template for output names. outtmpl: Template for output names.
ignoreerrors: Do not stop on download errors. ignoreerrors: Do not stop on download errors.
ratelimit: Download speed limit, in bytes/sec. ratelimit: Download speed limit, in bytes/sec.
nooverwrites: Prevent overwriting files.
""" """
_params = None _params = None
@ -286,6 +287,9 @@ class FileDownloader(object):
except (ValueError, KeyError), err: except (ValueError, KeyError), err:
retcode = self.trouble('ERROR: invalid output template or system charset: %s' % str(err)) retcode = self.trouble('ERROR: invalid output template or system charset: %s' % str(err))
continue continue
if self._params['nooverwrites'] and os.path.exists(filename):
self.to_stderr('WARNING: file exists: %s; skipping' % filename)
continue
try: try:
self.pmkdir(filename) self.pmkdir(filename)
except (OSError, IOError), err: except (OSError, IOError), err:
@ -976,6 +980,8 @@ if __name__ == '__main__':
dest='ratelimit', metavar='L', help='download rate limit (e.g. 50k or 44.6m)') dest='ratelimit', metavar='L', help='download rate limit (e.g. 50k or 44.6m)')
parser.add_option('-a', '--batch-file', parser.add_option('-a', '--batch-file',
dest='batchfile', metavar='F', help='file containing URLs to download') 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() (opts, args) = parser.parse_args()
# Batch file verification # Batch file verification
@ -1031,6 +1037,7 @@ if __name__ == '__main__':
or u'%(id)s.%(ext)s'), or u'%(id)s.%(ext)s'),
'ignoreerrors': opts.ignoreerrors, 'ignoreerrors': opts.ignoreerrors,
'ratelimit': opts.ratelimit, 'ratelimit': opts.ratelimit,
'nooverwrites': opts.nooverwrites,
}) })
fd.add_info_extractor(youtube_search_ie) fd.add_info_extractor(youtube_search_ie)
fd.add_info_extractor(youtube_pl_ie) fd.add_info_extractor(youtube_pl_ie)