diff --git a/libsaria/collection/library.py b/libsaria/collection/library.py index 69bb022e..7b9132b0 100644 --- a/libsaria/collection/library.py +++ b/libsaria/collection/library.py @@ -22,12 +22,12 @@ badfiles = set() ttable = dict() for s in string.punctuation: - ttable[ord(s)] = "" + ttable[ord(s)] = u"" for s in string.lowercase: ttable[ord(s)] = ord(s) - 32 def reset(): - from libsaria.trees import FSTree, DLFSTree + from libsaria.trees import FSTree, DLFSTree, DLValTree from tree import DLTree from index import Index @@ -41,7 +41,7 @@ def reset(): sources = FSTree() fs_tree = DLFSTree() - tag_tree = DLTree() + tag_tree = DLValTree() index = Index() tracks = dict() size = 0 @@ -49,32 +49,30 @@ def reset(): #save() def load(): - #global fs_tree - #global tag_tree + global fs_tree + global tag_tree #global index global tracks global sources #global size #global songs - reset() objects = libsaria.data.load("library", ".lib") - if objects == None or len(objects) != 3: + if objects == None or len(objects) != 4: #if objects == None or len(objects) != 6: reset() return - (sources, tracks) = objects + (sources, tracks, fs_tree, tag_tree) = objects #(fs_tree, tag_tree, index, tracks, next_id, size) = objects libsaria.event.start("POSTLIBLOAD") def save(): global sources - libsaria.data.save( (sources, tracks), "library", ".lib") + libsaria.data.save( (sources, tracks, fs_tree, tag_tree), + "library", ".lib") def walk(): - return [] - for tag in tag_tree.walk_forwards(): - #yield tag[3] - pass + for tag in tag_tree.walk(): + yield tag[3] def file_to_id(file): global fs_tree @@ -166,17 +164,24 @@ def insert_track(path, ref): global tracks global ttable global fs_tree + global tag_tree tags = ref.tag() audio = ref.audioProperties() - id = os.stat(path).st_ino + ino = os.stat(path).st_ino track = Track(tags, audio) artist = tags.artist or u"Unknown Artist" album = tags.album or u"Unknown Album" title = tags.title or u"Unknown Title" fs = fs_tree.insert_path(path) + tag = tag_tree.insert( [artist.translate(ttable), + album.translate(ttable), + title.translate(ttable), ino], + [artist, album, title, ino] + ) track.fs = fs - tracks[id] = track + track.tags = tag + tracks[ino] = track def update_path(path): global badfiles diff --git a/libsaria/collection/track.py b/libsaria/collection/track.py index a8b9c0ca..f3de3970 100644 --- a/libsaria/collection/track.py +++ b/libsaria/collection/track.py @@ -21,4 +21,4 @@ class Track: self.lenstr = lenstr self.fs = None - #self.tags = None + self.tags = None