#!/usr/bin/env python import sys import os import getopt import subprocess def unixPath(path): path = path.replace(' ','\ ') path = path.replace("'","\\'") path = path.replace("(","\\(") path = path.replace(")","\\)") path = path.replace("{","\\{") path = path.replace("}","\\}") path = path.replace('&','\&') return path class convertMp3ToM4b: def __init__(self): print "Start" self.workDir = os.getcwd() self.baseDir = os.path.basename(self.workDir) self.outName = unixPath(self.baseDir)+".m4a" print self.outName self.convert() def convert(self): listd = os.listdir(self.workDir) listif = [] for name in listd: if os.path.splitext(name)[1].lower() == ".mp3": listif.append(name) listif.sort() cmd1 = ["cat"] + listif cmd2 = ["ffmpeg", "-i","-","-ab","128","-sameq",self.outName] p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE) p2 = subprocess.Popen(cmd2, stdin=p1.stdout, stdout=subprocess.PIPE) out = p2.communicate() if out[0] or out[1]: print "error converting" print output[0] print output[1] class mainclass: def __init__(self): convertMp3ToM4b() mainclass()