72 lines
1.5 KiB
Python
72 lines
1.5 KiB
Python
# 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
|