diff --git a/libsaria/collection/collection.py b/libsaria/collection/collection.py index 14c603fc..9f87339b 100644 --- a/libsaria/collection/collection.py +++ b/libsaria/collection/collection.py @@ -100,7 +100,7 @@ class TrackRecord: self.length = 0 self.count = 0 self.year = 0 - self.like = None + #self.like = None self.fs = None self.tags = None @@ -110,11 +110,19 @@ class Collection2: def __init__(self): self.fs_tree = None self.tag_tree = None + self.records = None + self.next_record = 0 + + def save(self, file): + libsaria.data.save( + [self.fs_tree, self.tag_tree, self.records, self.next_record], + file, "") def reset(self): from tree import DLTree self.fs_tree = DLTree() self.tag_tree = DLTree() + self.records = dict() def disp(self): pass @@ -122,3 +130,28 @@ class Collection2: #print #print #self.tag_tree.disp() + + def insert_allocate(self, components, ref): + t = ref.tag() + artist = str(t.artist) + album = str(t.album) + title = str(t.title) + audio = ref.audioProperties() + if artist == "": + artist = "Unknown Artist" + if album == "": + album = "Unknown Album" + if title == "": + title = "Unknown Title" + + record = TrackRecord(t.year, audio.length) + + id = self.next_record + self.next_record += 1 + + fs = self.fs_tree.insert(components + [id]) + tags = self.tag_tree.insert([artist, album, title, id]) + + record.fs = fs + record.tags = tags + self.records[id] = record diff --git a/libsaria/collection/filters.py b/libsaria/collection/filters.py index 667ee0d3..b7a80a40 100644 --- a/libsaria/collection/filters.py +++ b/libsaria/collection/filters.py @@ -10,43 +10,23 @@ walk = libsaria.path.walk join = libsaria.path.join splitext = libsaria.path.splitext -Record = collection.TrackRecord - class Library(collection.Collection2): def __init__(self): + collection.Collection2.__init__(self) self.badfiles = set() pass - def save(self): - libsaria.data.save((self.fs_tree, self.tag_tree), "DLTree_test", "") + #def save(self): + #libsaria.data.save((self.fs_tree, self.tag_tree), "DLTree_test", "") + # libsaria.data.save(self, "DLTree_test", "") def scan(self, path): print "Library scanning %s" % path self.reset() self.update(path) - self.save() + self.save("DLTree_test") self.disp() - def insert(self, components, ref): - t = ref.tag() - artist = str(t.artist) - album = str(t.album) - title = str(t.title) - audio = ref.audioProperties() - if artist == "": - artist = "Unknown Artist" - if album == "": - album = "Unknown Album" - if title == "": - title = "Unknown Title" - - record = Record(t.year, audio.length) - - fs = self.fs_tree.insert(components + [record]) - tags = self.tag_tree.insert([artist, album, title, record]) - record.fs = fs - record.tags = tags - def update(self, path): badfiles = self.badfiles FileRef = libsaria.collection.FileRef @@ -65,7 +45,9 @@ class Library(collection.Collection2): badfiles.add(ext) continue try: - self.insert(split_root + [file], ref) - except Exception, e: - #print e + self.insert_allocate(split_root + [file], ref) + except UnicodeEncodeError: pass + #except Exception, e: + # print e + # pass diff --git a/libsaria/collection/tree.py b/libsaria/collection/tree.py index a1dc7dd8..82371e4a 100644 --- a/libsaria/collection/tree.py +++ b/libsaria/collection/tree.py @@ -64,13 +64,21 @@ class Tree(dict): class DLTree: def __init__(self, parent=None): self.parent = parent - self.children = dict() + self.children = None def disp(self, level=0): space = " " * level + children = self.children - for key,value in self.children.iteritems(): - if key.__class__ == str: + if children == None: + return + + keys = children.keys() + keys.sort() + + for key in keys: + if key.__class__ == str or key.__class__ == int: + value = children[key] print space, key value.disp(level+1) @@ -92,6 +100,11 @@ class DLTree: child = None try: child = self.children[cmp] + except TypeError: + self.children = dict() + child = DLTree(self) + self.children[cmp] = child + self.children[child] = cmp except KeyError: child = DLTree(self) self.children[cmp] = child diff --git a/libsaria/data.py b/libsaria/data.py index f2b5bc46..eaf04d48 100644 --- a/libsaria/data.py +++ b/libsaria/data.py @@ -2,6 +2,7 @@ from libsaria import path import cPickle as pickle +#import pickle plugin = None PROTO = pickle.HIGHEST_PROTOCOL diff --git a/tests/converging.py b/tests/dl_tree.py similarity index 100% rename from tests/converging.py rename to tests/dl_tree.py