From a1bae3e6c8f81ec4838a0f2c28d1e0b85858a730 Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 10 Jul 2017 18:41:14 +0200 Subject: Add option for overwrite or not --- convert.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/convert.py b/convert.py index 10e346d..d0c8e64 100755 --- a/convert.py +++ b/convert.py @@ -9,16 +9,24 @@ import pexpect import time import datetime -if len(sys.argv) == 3: - sourcedir = sys.argv[1] - outdir = sys.argv[2] +if len(sys.argv) >= 3 and len(sys.argv) <= 4: + if len(sys.argv) == 3: + sourcedir = sys.argv[1] + outdir = sys.argv[2] + arg = "-n" + else: + sourcedir = sys.argv[2] + outdir = sys.argv[3] + arg = sys.argv[1] if not os.path.isdir(sourcedir): print("No such file or directory: '"+str(sourcedir)+"'") sys.exit() else: print("Simple tool for convert mp4 file to mp3") - print("Usage:\nconvert.py [SOURCE] [DESTINATION]") + print("Usage:\nconvert.py [-n|-y] [SOURCE] [DESTINATION]") + print(" -n ffmpeg: Do not overwrite output files, and exit immediately if a specified output file already exists. (Default option)") + print(" -y ffmpeg: Overwrite output files without asking.") def dirSize(path,ext1,ext2): list_dir = [] @@ -41,7 +49,7 @@ for file in sorted(os.listdir(sourcedir)): print("Converting : "+name) count += 1 #cmd = ["ffmpeg", "-n", "-i", sourcedir+"/"+name+".mp4", "-c:a", "libmp3lame", outdir+"/"+name+".mp3"]² - 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'" thread = pexpect.spawn(cmd) cpl = thread.compile_pattern_list([pexpect.EOF,"frame= *\d+",'(.+)']) -- cgit v1.2.1