summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xconvert.py13
1 files 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+",'(.+)'])