Track tags in another double linked tree. Create a record for each

track linking to each tree.  Create a library filter for creating a
library.
This commit is contained in:
Bryan Schumaker 2010-10-01 21:33:19 -04:00
parent 8221411ca2
commit 31b470e597
5 changed files with 96 additions and 31 deletions

View File

@ -16,7 +16,8 @@ QUEUE = 2
import collection
library = collection.Collection()
library2 = collection.Collection2()
import filters
library2 = filters.Library()
cur_lib_id = -1

View File

@ -94,40 +94,31 @@ class Collection:
insert(FileRef(file), file)
except Exception,e:
pass
#print Exception, e
#print e
class TrackRecord:
def __init__(self, year, length):
self.length = 0
self.count = 0
self.year = 0
self.like = None
self.fs = None
self.tags = None
class Collection2:
def __init__(self):
self.tree = None
def save(self):
from libsaria import data
data.save((self.fs_tree), "DLTree_test", "")
def scan(self, path):
print "Collection2 scanning %s" % path
self.reset()
self.update(path)
self.save()
self.fs_tree.disp()
self.fs_tree = None
self.tag_tree = None
def reset(self):
from tree import DLTree
self.fs_tree = DLTree()
self.fs_tree = DLTree()
self.tag_tree = DLTree()
def update(self, path):
sep = libsaria.path.sep
fs = self.fs_tree
splitext = libsaria.path.splitext
badfiles = set([".jpg", ".db", ".ape"])
for root,dirs,files in libsaria.path.walk(path):
root = root.strip(sep)
split_root = root.split(sep)
for file in files:
ext = splitext(file)[1]
if ext in badfiles:
continue
fs.insert(split_root + [file])
#print split_root, file
def disp(self):
pass
#self.fs_tree.disp()
#print
#print
#self.tag_tree.disp()

View File

@ -0,0 +1,71 @@
# Bryan Schumaker (10/1/2010)
import libsaria
import collection
from libsaria import data
sep = libsaria.path.sep
walk = libsaria.path.walk
join = libsaria.path.join
splitext = libsaria.path.splitext
Record = collection.TrackRecord
class Library(collection.Collection2):
def __init__(self):
self.badfiles = set()
pass
def save(self):
libsaria.data.save((self.fs_tree, self.tag_tree), "DLTree_test", "")
def scan(self, path):
print "Library scanning %s" % path
self.reset()
self.update(path)
self.save()
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
for root,dirs,files in walk(path):
stripped_root = root.strip(sep)
split_root = stripped_root.split(sep)
for file in files:
ext = splitext(file)[1]
if ext in badfiles:
continue
path = join(root, file)
try:
ref = FileRef(path)
except:
badfiles.add(ext)
continue
try:
self.insert(split_root + [file], ref)
except Exception, e:
#print e
pass

View File

@ -97,4 +97,5 @@ class DLTree:
self.children[cmp] = child
self.children[child] = cmp
if len(path) > 1:
child.insert(path[1:])
return child.insert(path[1:])
return self

View File

@ -1,5 +1,6 @@
# Bryan Schumaker (10/1/2010)
from libsaria import collection