From eeaf382d813ad0ea7768cf4a9b169e702ee097a5 Mon Sep 17 00:00:00 2001 From: NeodarZ Date: Sun, 15 Oct 2017 13:53:27 +0200 Subject: Fix bug with end slash in source dir path --- convert.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/convert.py b/convert.py index 3b1db72..3951ab1 100755 --- a/convert.py +++ b/convert.py @@ -9,6 +9,10 @@ import pexpect import time import datetime +def path_rm_end_slash(string): + string = re.sub("\/$", "", string) + return(string) + if len(sys.argv) >= 3 and len(sys.argv) <= 4: if len(sys.argv) == 3: sourcedir = sys.argv[1] @@ -40,6 +44,9 @@ def dirSize(path,ext1,ext2): count += 1 return count +if not os.path.exists(outdir): + os.makedirs(outdir) + total = dirSize(sourcedir, ".mp4", ".mkv") count = 0 @@ -49,13 +56,13 @@ for file in sorted(os.listdir(sourcedir)): if file.endswith(".mp4"): 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.") + if os.path.getsize(path_rm_end_slash(sourcedir)+"/"+name+".mp4") == os.path.getsize(outdir+"/"+name+".mp3"): + print("File "+path_rm_end_slash(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'" + cmd = "ffmpeg "+arg+" -i '"+path_rm_end_slash(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