diff --git a/libsaria/collection/library.py b/libsaria/collection/library.py index 5b89a5ed..15e281bb 100644 --- a/libsaria/collection/library.py +++ b/libsaria/collection/library.py @@ -1,6 +1,10 @@ # Bryan Schumaker (11/05/2010) +import tagpy import libsaria +import string +from track import Track +splitext = libsaria.path.splitext fs_tree = None tag_tree = None @@ -11,7 +15,16 @@ sources = None size = None visible = None +FileRef = tagpy.FileRef + filtered = False +badfiles = set() + +ttable = dict() +for s in string.punctuation: + ttable[ord(s)] = "" +for s in string.lowercase: + ttable[ord(s)] = ord(s) - 32 def reset(): from libsaria.trees import FSTree @@ -35,29 +48,31 @@ def reset(): next_id = 0 size = 0 visible = set() - save() + #save() def load(): #global fs_tree #global tag_tree #global index - #global tracks + global tracks global next_id global sources #global size #global songs + reset() objects = libsaria.data.load("library", ".lib") - if objects == None or len(objects) != 2: + if objects == None or len(objects) != 3: #if objects == None or len(objects) != 6: reset() return - (sources, next_id) = objects + (sources, tracks, next_id) = objects + print next_id #(fs_tree, tag_tree, index, tracks, next_id, size) = objects libsaria.event.start("POSTLIBLOAD") def save(): global sources - libsaria.data.save( (sources, next_id), "library", ".lib") + libsaria.data.save( (sources, tracks, next_id), "library", ".lib") def walk(): return [] @@ -151,9 +166,36 @@ def scan(path): update() save() +def insert_track(path, ref): + global next_id + global tracks + global ttable + global fs_tree + tags = ref.tag() + audio = ref.audioProperties() + 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" + tracks[next_id] = track + next_id += 1 + def update_path(path): + global badfiles tree = libsaria.path.make_tree(path) - print path, len(tree) + for path in tree.walk_paths(): + ext = splitext(path)[1] + if ext in badfiles: + continue + try: + ref = FileRef(path) + except: + badfiles.add(ext) + continue + try: + insert_track(path, ref) + except Exception, e: + print e def update(): global sources