From cb498521fcb38a9cca2d8b6d481e0063eeb1c91c Mon Sep 17 00:00:00 2001 From: neodarz Date: Wed, 12 Jul 2017 14:53:04 +0200 Subject: Add function to know if file exist --- convert.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/convert.py b/convert.py index 89dd19b..3b1db72 100755 --- a/convert.py +++ b/convert.py @@ -47,7 +47,12 @@ for file in sorted(os.listdir(sourcedir)): try: name = file[:file.rfind(".")] if file.endswith(".mp4"): - print("Converting : "+name) + exist = False + if os.path.isfile(outdir+"/"+name+".mp3"): + if os.path.getsize(sourcedir+"/"+name+".mp3") == os.path.getsize(outdir+"/"+name+".mp3"): + print("File "+sourcedir+"/"+name+".mp3 already exist. Use -y for overwrite.") + else: + print("Converting : "+name) count += 1 #cmd = ["ffmpeg", "-n", "-i", sourcedir+"/"+name+".mp4", "-c:a", "libmp3lame", outdir+"/"+name+".mp3"]² cmd = "ffmpeg "+arg+" -i '"+sourcedir+"/"+name+".mp4' -c:a libmp3lame '"+outdir+"/"+name+".mp3'" @@ -77,7 +82,7 @@ for file in sorted(os.listdir(sourcedir)): if re.match(r'.*time=.*', str(unknown_line)): timeRange = time.strptime(str(unknown_line).split("=")[2].split()[0].split('.')[0],'%H:%M:%S') timeRangeS = datetime.timedelta(hours=timeRange.tm_hour,minutes=timeRange.tm_min,seconds=timeRange.tm_sec).total_seconds() - print(str(round(100*timeRangeS/totalRangeS, 1))+"% / 100%", end='\r') + print(str(round(100*timeRangeS/totalRangeS, 1))+"% / 100% "+str(exist), end='\r') thread.close -- cgit v1.2.1