#!/usr/bin/python # # (c) 2005 Tobias Ulbricht # # stupid little script # wanted to abstract a cue file, but ran out of motivation half way through # it can do: convert a .wav file into several wav files, using a cue sheet # and ecasound to split the files. # # # just found that the flac encoder might do the whole stuff with the --cuesheet # option - sigh - well a practice in scripting anyway.. import string import os class cuefile: def __init__(self,filename): self.filename = filename self.fd = open(filename, "r") if (self.fd == 0): throw() self.tracks = [] self.offsets = [] self.offsets_secs = [] self.audiofilename = self.parse("FILE")[0] def parse(self, token): list = [] self.fd.seek(0) for line in self.fd.readlines(): line = string.lstrip(line) if string.find(line, token) != -1: list.append(string.rstrip(line)) return list def readtracks(self): self.tracks = self.parse("TRACK") def readoffsets(self): self.offsets = self.parse("INDEX") def readaudiotracks(self): self.readtracks() self.readoffsets() pos = 0 for i in self.tracks: if string.split(i, " ")[2] == "AUDIO": slist = string.split(self.offsets[pos], " ") slist = string.split(slist[2], ":") secs = string.atoi(slist[0])*60 +string.atoi(slist[1]) + string.atoi(slist[2])/75.0 self.offsets_secs.append(secs) print "audio track no. " + str(pos) + " found. Offset: " + str(secs) + " seconds." pos += 1 def close(self): self.fd.close() mycue = cuefile("test.cue") mycue.readaudiotracks() lastoffset = 0 pos = 0 for i in mycue.offsets_secs : length = i - lastoffset if (length != 0): command = 'ecasound -i:"' + string.split(mycue.audiofilename," ")[1] + '" -y ' +str(lastoffset) +' -t ' + str(length) + ' -o ' + str(pos) + '.wav' print "Executing command: \'" + command +"\'" os.system( command ) pos += 1 mycue.close()