2005-06-12 20:03:22 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
## this is a dirty, lame hack by a dirty, lame guy
|
|
|
|
## - reads a .m3u file (e.g. generated by xmms)
|
|
|
|
## - converts any audiofile to wavefiles using incredible mplayer
|
|
|
|
## - provides normalized wavefiles using transcode
|
|
|
|
## - burns an audio-cd
|
|
|
|
# !!feel free to copy, modify, redistribute and at most _use_ it!!
|
2005-08-09 13:24:00 +02:00
|
|
|
# AGE/02004
|
2005-06-12 20:03:22 +02:00
|
|
|
|
2005-08-09 13:24:00 +02:00
|
|
|
import os,sys
|
2005-06-12 20:03:22 +02:00
|
|
|
import string
|
|
|
|
|
2005-08-09 13:24:00 +02:00
|
|
|
#recorder = "ATAPI:0,0,0" #fuer cdrecord mit 2.6 kernel und ide brenner
|
|
|
|
recorder = "0,0,0" #fuer cdrecord mit 2.6 kernel und ide brenner
|
|
|
|
|
|
|
|
__doc__ = """usage: %s file.m3u wav-destination""" % sys.argv[0]
|
|
|
|
|
|
|
|
################
|
|
|
|
### init checks
|
|
|
|
try:
|
|
|
|
m3ufile = sys.argv[1]
|
|
|
|
wavdir = sys.argv[2]
|
|
|
|
if not os.access(wavdir,os.W_OK) :
|
|
|
|
print "%s not writeable" % wavdir
|
|
|
|
sys.exit(3)
|
|
|
|
except:
|
|
|
|
print >>sys.stderr, __doc__
|
|
|
|
sys.exit(1)
|
|
|
|
|
2005-06-12 20:03:22 +02:00
|
|
|
|
|
|
|
print "\nDirty, lame hack in action:\n"
|
|
|
|
################
|
2005-08-09 13:24:00 +02:00
|
|
|
### m3u einlesen
|
2005-06-12 20:03:22 +02:00
|
|
|
try:
|
|
|
|
temp = open(m3ufile,"r")
|
|
|
|
m3u = temp.read()
|
|
|
|
temp.close()
|
|
|
|
except:
|
|
|
|
print "I can't find the .m3u file"
|
2005-08-09 13:24:00 +02:00
|
|
|
sys.exit(2)
|
2005-06-12 20:03:22 +02:00
|
|
|
# M's Kommentar Schnibbler
|
|
|
|
notfound = 0
|
|
|
|
while notfound == 0:
|
|
|
|
startpos = string.find(m3u,"#")
|
|
|
|
if startpos <0:
|
|
|
|
notfound +=1
|
|
|
|
endpos = string.find(m3u,"\n",startpos)
|
|
|
|
cutme = m3u[startpos:endpos]
|
|
|
|
m3u = string.replace(m3u,cutme,"")
|
|
|
|
|
|
|
|
valuepairs = string.split(m3u,"\n")
|
|
|
|
m3u = []
|
|
|
|
for i in valuepairs:
|
|
|
|
if i != "":
|
|
|
|
m3u.append(i)
|
|
|
|
# im m3u-array stehen jetzt hoffentlich ;) nur noch pfadangaben
|
2005-08-09 13:24:00 +02:00
|
|
|
# checken ob's stimmt & und ob alle files existieren
|
|
|
|
abort = 0
|
2005-06-12 20:03:22 +02:00
|
|
|
for i in m3u:
|
|
|
|
if not os.path.exists(i):
|
2005-08-09 13:24:00 +02:00
|
|
|
abort = abort + 1
|
|
|
|
print "===> not found: %s " % i
|
2005-06-12 20:03:22 +02:00
|
|
|
m3u.remove(i)
|
2005-08-09 13:24:00 +02:00
|
|
|
if abort > 0:
|
|
|
|
print "\nI can't find %i audiofiles - giving up" % abort
|
|
|
|
#TODO
|
|
|
|
# abfrage ob ohne die files mit gekuertzter m3u weiter gemacht werden
|
|
|
|
# soll..
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
print "\nI found %i audiofiles to convert, normalize and burn:" % len(m3u)
|
|
|
|
|
2005-06-12 20:03:22 +02:00
|
|
|
|
|
|
|
##############
|
2005-08-09 13:24:00 +02:00
|
|
|
### ogg/mp3 -> wav
|
2005-06-12 20:03:22 +02:00
|
|
|
count = 0
|
|
|
|
for file in m3u:
|
|
|
|
count+=1
|
2005-08-09 13:24:00 +02:00
|
|
|
# fuehrende nullen ranballern
|
|
|
|
#if count < 10:
|
|
|
|
#count0 = "0"+str(count)
|
|
|
|
#else:
|
|
|
|
#count0 = str(count)
|
|
|
|
count0 = "%.3i" % count
|
|
|
|
command = "mplayer \""+file+"\" -vc dummy -vo null -ao pcm -aofile "+wavdir+"/"+str(count0)+".wav &> /dev/null"
|
2005-06-12 20:03:22 +02:00
|
|
|
print "\nexec: "+command
|
|
|
|
session = os.popen(command,"w")
|
|
|
|
session.write("")
|
|
|
|
session.flush()
|
|
|
|
session.close()
|
|
|
|
|
|
|
|
#########################
|
|
|
|
### wav -> normalized wav
|
|
|
|
wavefiles = os.listdir(wavdir)
|
|
|
|
for wave in wavefiles:
|
|
|
|
command = "transcode -J normalize -y wav -i "+wavdir+"/"+wave+" -m "+wavdir+"/"+ wave+".norm &> /dev/null"
|
|
|
|
print "\nexec: "+command
|
|
|
|
session = os.popen(command,"w")
|
|
|
|
session.write("")
|
|
|
|
session.flush()
|
|
|
|
session.close()
|
|
|
|
|
|
|
|
##################
|
|
|
|
### wav -> audiocd
|
|
|
|
command = "sudo cdrecord -v -dev="+recorder+" -pad -audio "+wavdir+"/*.wav.norm"
|
|
|
|
print "\nexec: "+command
|
2005-08-09 13:24:00 +02:00
|
|
|
print "\nwarning: If this fails, try to change the \"recorder\" variable!"
|
2005-06-12 20:03:22 +02:00
|
|
|
session = os.popen(command,"w")
|
|
|
|
session.write("")
|
|
|
|
session.flush()
|
|
|
|
session.close()
|
|
|
|
|
2005-08-09 13:24:00 +02:00
|
|
|
#print "\n That's it! Eine Stunde coden und dafuer jetzt den Sommer geniessen..."
|
|
|
|
print "done"
|