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:
parent
8221411ca2
commit
31b470e597
|
@ -16,7 +16,8 @@ QUEUE = 2
|
||||||
import collection
|
import collection
|
||||||
library = collection.Collection()
|
library = collection.Collection()
|
||||||
|
|
||||||
library2 = collection.Collection2()
|
import filters
|
||||||
|
library2 = filters.Library()
|
||||||
|
|
||||||
cur_lib_id = -1
|
cur_lib_id = -1
|
||||||
|
|
||||||
|
|
|
@ -94,40 +94,31 @@ class Collection:
|
||||||
insert(FileRef(file), file)
|
insert(FileRef(file), file)
|
||||||
except Exception,e:
|
except Exception,e:
|
||||||
pass
|
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:
|
class Collection2:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.tree = None
|
self.fs_tree = None
|
||||||
|
self.tag_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()
|
|
||||||
|
|
||||||
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()
|
||||||
|
|
||||||
def update(self, path):
|
def disp(self):
|
||||||
sep = libsaria.path.sep
|
pass
|
||||||
fs = self.fs_tree
|
#self.fs_tree.disp()
|
||||||
splitext = libsaria.path.splitext
|
#print
|
||||||
badfiles = set([".jpg", ".db", ".ape"])
|
#print
|
||||||
for root,dirs,files in libsaria.path.walk(path):
|
#self.tag_tree.disp()
|
||||||
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
|
|
||||||
|
|
|
@ -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
|
|
@ -97,4 +97,5 @@ class DLTree:
|
||||||
self.children[cmp] = child
|
self.children[cmp] = child
|
||||||
self.children[child] = cmp
|
self.children[child] = cmp
|
||||||
if len(path) > 1:
|
if len(path) > 1:
|
||||||
child.insert(path[1:])
|
return child.insert(path[1:])
|
||||||
|
return self
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Bryan Schumaker (10/1/2010)
|
# Bryan Schumaker (10/1/2010)
|
||||||
|
|
||||||
|
|
||||||
from libsaria import collection
|
from libsaria import collection
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue