2013-05-17 22:18:24 -07:00
|
|
|
from optparse import OptionParser
|
|
|
|
import os, shlex, subprocess
|
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option('-i', '--input', dest='fInput')
|
|
|
|
parser.add_option('-o', '--output', dest='fOutput')
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
inputDir = options.fInput
|
|
|
|
outputDir = options.fOutput
|
|
|
|
|
|
|
|
if not outputDir.endswith("/"):
|
|
|
|
outputDir += "/"
|
|
|
|
|
|
|
|
def extractCurrentDirectory(dir):
|
|
|
|
return dir.replace(inputDir, "").replace("/", "", 1)
|
|
|
|
|
2013-05-18 07:44:48 -07:00
|
|
|
def replace_last(source_string, replace_what, replace_with):
|
|
|
|
head, sep, tail = source_string.rpartition(replace_what)
|
|
|
|
return head + replace_with + tail
|
|
|
|
|
2013-05-17 22:18:24 -07:00
|
|
|
for root, dirs, files in os.walk(inputDir):
|
2013-05-18 07:44:48 -07:00
|
|
|
os.chdir(root)
|
2013-05-17 22:18:24 -07:00
|
|
|
root = extractCurrentDirectory(root)
|
|
|
|
|
|
|
|
# Create the child directory if it doesn't exist so we can put files in it
|
|
|
|
if not os.path.exists(outputDir + root):
|
|
|
|
os.makedirs(outputDir + root)
|
|
|
|
|
|
|
|
for name in files:
|
|
|
|
if name.endswith(".flac"):
|
2013-05-18 07:44:48 -07:00
|
|
|
print("Transcoding File: %s" % name)
|
|
|
|
output = replace_last((outputDir + root + "/" + name), "flac", "ogg")
|
|
|
|
command = shlex.split("ffmpeg -i \"%s\" -f ogg -c:a libvorbis -q 8 -map 0:0 \"%s\"" % (name, output))
|
2013-05-17 22:18:24 -07:00
|
|
|
p = subprocess.call(command)
|