1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-29 13:42:37 +00:00

do not overwrite existing files

This commit is contained in:
andreabravetti 2012-05-28 15:07:38 +03:00
parent f36cd07685
commit ff52a69b91

View file

@ -166,6 +166,22 @@ def sanitize_open(filename, open_mode):
It returns the tuple (stream, definitive_file_name).
"""
# do not overwrite existing files
if filename != u'-':
if filename.endswith(u'.part'):
_addpart = u'.part'
_name, _ext = os.path.splitext(filename[:-len(u'.part')])
filename = filename[:-len(u'.part')]
else:
_addpart = u''
_name, _ext = os.path.splitext(filename)
_count = 0
while os.path.isfile(filename):
_count += 1
filename = "%s-%s%s" % (_name, _count, _ext)
filename = "%s%s" % (filename,_addpart)
try:
if filename == u'-':
if sys.platform == 'win32':