mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-26 04:02:11 +00:00
do not overwrite existing files
This commit is contained in:
parent
f36cd07685
commit
ff52a69b91
1 changed files with 16 additions and 0 deletions
|
@ -166,6 +166,22 @@ def sanitize_open(filename, open_mode):
|
||||||
|
|
||||||
It returns the tuple (stream, definitive_file_name).
|
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:
|
try:
|
||||||
if filename == u'-':
|
if filename == u'-':
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
|
|
Loading…
Reference in a new issue