From d79975860209a7b5b382fb155b04cc663cdc5e6e Mon Sep 17 00:00:00 2001 From: Colin McCabe Date: Sun, 13 Dec 2009 15:28:05 -0800 Subject: [PATCH] Add lossy_mirror script --- lossy_mirror.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-) create mode 100755 lossy_mirror.py diff --git a/lossy_mirror.py b/lossy_mirror.py new file mode 100755 index 0000000..53d0a65 --- /dev/null +++ b/lossy_mirror.py @@ -0,0 +1,72 @@ +#!/usr/bin/python + +# +# lossy_mirror.py +# +# Given a path to a folder of flac files, create a folder full of mp3 files +# based on them and named similarly. +# +# Colin McCabe +# + +import sys, getopt, os + +## Functions +def my_system(cmd): + print cmd + ret = os.system(cmd) + if ret != 0: + print "command " + cmd + " failed with error code " + str(ret) + sys.exit(1) + +def quote(string): + return "\"" + string + "\"" + +## Parse options +try: + optlist, list = getopt.getopt(sys.argv[1:], ':hi:') +except getopt.GetoptError: + print "autoftp [-v][-p][-h]" + sys.exit(1) + +input_folder = "" +for opt in optlist: + print opt + if opt[0] == '-h': + Usage() + if opt[0] == '-i': + input_folder = opt[1] + +## Verify options +if input_folder == "": + print 'You must give an input folder with -i' + sys.exit(1) + +input_folder = input_folder.rstrip('/') + +if not input_folder.endswith(' [LL]'): + print "Input folder \"" + input_folder + "\" doesnt end with \"[LL]\"" + sys.exit(1) + +output_folder = input_folder[0:-5] +abs_input_folder = os.path.abspath(input_folder) + +## Create new directory +os.mkdir(output_folder) +os.chdir(output_folder) + +for file in os.listdir(abs_input_folder): + if file.endswith('.flac'): + infile = abs_input_folder + "/" + file + wavfile = "./" + file + ".wav" + r = wavfile.rfind('.flac.wav') + mp3file = wavfile[0:r] + ".mp3" + my_system("flac -c -d " + quote(infile) + " > " + quote(wavfile)) + my_system("lame -q 1 -b 192 " + quote(wavfile) + " " + quote(mp3file)) + +for file in os.listdir("."): + if file.endswith('.wav'): + os.unlink(file) + +print "DONE" +sys.exit(0) -- 1.6.6.rc1.39.g9a42