# Bryan Schumaker (8/8/2010) import libsaria tag = None audio = None ins_table = None ins_index = None ins_tree = None class Collection: def __init__(self): self.tree = None #self.load() def __iter__(self): if not self.tree: self.load() for track in self.tree.walk(): yield track def scan(self, path): print "Scanning path:", path global ins_table global ins_index global ins_tree self.reset() ins_table = self.table.insert ins_index = self.index.insert ins_tree = self.tree. insert self.update(path) self.save() def reset(self): print "Resetting collection ... " from table import Table from index import Index from tree import Tree self.table = Table() self.index = Index() self.tree = Tree() def save(self): from libsaria import data data.save((self.table, self.index, self.tree), "library", "") def load(self): from libsaria import data objects = data.load("library", "") if objects == None: self.reset() return (self.table, self.index, self.tree) = objects def insert(self, file, filepath): global tag global audio global ins_table global ins_index global ins_tree tags = tag(file) audio_prop = audio(file) if tags.artist == u"": tags.artist = "Unknown Artist" if tags.album == u"": tags.album = "Unknown Album" if tags.title == u"": tags.title = "Unknown Title" list = [tags.artist, tags.album, tags.title] id = ins_table(list) ins_index(id, list) list.append(id) ins_tree(list, tags, audio_prop, filepath) def update(self, path): global tag global audio FileRef = libsaria.collection.FileRef join = libsaria.path.join insert = self.insert tag = FileRef.tag audio = FileRef.audioProperties for root,dirs,files in libsaria.path.walk(path): for file in files: file = join(root,file) try: insert(FileRef(file), file) except Exception,e: pass #print Exception, e #print e