More work with collections based on doubly linked trees
This commit is contained in:
parent
31b470e597
commit
ab29b2cb2b
|
@ -100,7 +100,7 @@ class TrackRecord:
|
||||||
self.length = 0
|
self.length = 0
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.year = 0
|
self.year = 0
|
||||||
self.like = None
|
#self.like = None
|
||||||
|
|
||||||
self.fs = None
|
self.fs = None
|
||||||
self.tags = None
|
self.tags = None
|
||||||
|
@ -110,11 +110,19 @@ class Collection2:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.fs_tree = None
|
self.fs_tree = None
|
||||||
self.tag_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):
|
def reset(self):
|
||||||
from tree import DLTree
|
from tree import DLTree
|
||||||
self.fs_tree = DLTree()
|
self.fs_tree = DLTree()
|
||||||
self.tag_tree = DLTree()
|
self.tag_tree = DLTree()
|
||||||
|
self.records = dict()
|
||||||
|
|
||||||
def disp(self):
|
def disp(self):
|
||||||
pass
|
pass
|
||||||
|
@ -122,3 +130,28 @@ class Collection2:
|
||||||
#print
|
#print
|
||||||
#print
|
#print
|
||||||
#self.tag_tree.disp()
|
#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
|
||||||
|
|
|
@ -10,43 +10,23 @@ walk = libsaria.path.walk
|
||||||
join = libsaria.path.join
|
join = libsaria.path.join
|
||||||
splitext = libsaria.path.splitext
|
splitext = libsaria.path.splitext
|
||||||
|
|
||||||
Record = collection.TrackRecord
|
|
||||||
|
|
||||||
class Library(collection.Collection2):
|
class Library(collection.Collection2):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
collection.Collection2.__init__(self)
|
||||||
self.badfiles = set()
|
self.badfiles = set()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def save(self):
|
#def save(self):
|
||||||
libsaria.data.save((self.fs_tree, self.tag_tree), "DLTree_test", "")
|
#libsaria.data.save((self.fs_tree, self.tag_tree), "DLTree_test", "")
|
||||||
|
# libsaria.data.save(self, "DLTree_test", "")
|
||||||
|
|
||||||
def scan(self, path):
|
def scan(self, path):
|
||||||
print "Library scanning %s" % path
|
print "Library scanning %s" % path
|
||||||
self.reset()
|
self.reset()
|
||||||
self.update(path)
|
self.update(path)
|
||||||
self.save()
|
self.save("DLTree_test")
|
||||||
self.disp()
|
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):
|
def update(self, path):
|
||||||
badfiles = self.badfiles
|
badfiles = self.badfiles
|
||||||
FileRef = libsaria.collection.FileRef
|
FileRef = libsaria.collection.FileRef
|
||||||
|
@ -65,7 +45,9 @@ class Library(collection.Collection2):
|
||||||
badfiles.add(ext)
|
badfiles.add(ext)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
self.insert(split_root + [file], ref)
|
self.insert_allocate(split_root + [file], ref)
|
||||||
except Exception, e:
|
except UnicodeEncodeError:
|
||||||
#print e
|
|
||||||
pass
|
pass
|
||||||
|
#except Exception, e:
|
||||||
|
# print e
|
||||||
|
# pass
|
||||||
|
|
|
@ -64,13 +64,21 @@ class Tree(dict):
|
||||||
class DLTree:
|
class DLTree:
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.children = dict()
|
self.children = None
|
||||||
|
|
||||||
def disp(self, level=0):
|
def disp(self, level=0):
|
||||||
space = " " * level
|
space = " " * level
|
||||||
|
children = self.children
|
||||||
|
|
||||||
for key,value in self.children.iteritems():
|
if children == None:
|
||||||
if key.__class__ == str:
|
return
|
||||||
|
|
||||||
|
keys = children.keys()
|
||||||
|
keys.sort()
|
||||||
|
|
||||||
|
for key in keys:
|
||||||
|
if key.__class__ == str or key.__class__ == int:
|
||||||
|
value = children[key]
|
||||||
print space, key
|
print space, key
|
||||||
value.disp(level+1)
|
value.disp(level+1)
|
||||||
|
|
||||||
|
@ -92,6 +100,11 @@ class DLTree:
|
||||||
child = None
|
child = None
|
||||||
try:
|
try:
|
||||||
child = self.children[cmp]
|
child = self.children[cmp]
|
||||||
|
except TypeError:
|
||||||
|
self.children = dict()
|
||||||
|
child = DLTree(self)
|
||||||
|
self.children[cmp] = child
|
||||||
|
self.children[child] = cmp
|
||||||
except KeyError:
|
except KeyError:
|
||||||
child = DLTree(self)
|
child = DLTree(self)
|
||||||
self.children[cmp] = child
|
self.children[cmp] = child
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from libsaria import path
|
from libsaria import path
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
#import pickle
|
||||||
plugin = None
|
plugin = None
|
||||||
|
|
||||||
PROTO = pickle.HIGHEST_PROTOCOL
|
PROTO = pickle.HIGHEST_PROTOCOL
|
||||||
|
|
Loading…
Reference in New Issue