46 lines
791 B
Python
46 lines
791 B
Python
# Bryan Schumaker (8/8/2010)
|
|
|
|
import libsaria
|
|
|
|
class Collection:
|
|
def __init__(self):
|
|
pass
|
|
|
|
|
|
def scan(self, path):
|
|
print "Scanning path:", path
|
|
self.reset()
|
|
self.update(path)
|
|
|
|
|
|
def reset(self):
|
|
print "Erasing collection ... "
|
|
from table import Table
|
|
from index import Index
|
|
self.table = Table()
|
|
self.index = Index()
|
|
|
|
|
|
def insert(self, file):
|
|
tags = file.tag()
|
|
tuple = (tags.artist, tags.album, tags.title)
|
|
id = self.table.insert(tuple)
|
|
self.index.insert(id, tuple)
|
|
|
|
|
|
def update(self, path):
|
|
FileRef = libsaria.collection.FileRef
|
|
join = libsaria.path.join
|
|
insert = self.insert
|
|
|
|
for root,dirs,files in libsaria.path.walk(path):
|
|
for file in files:
|
|
file = join(root,file)
|
|
try:
|
|
insert(FileRef(file))
|
|
except Exception,e:
|
|
pass
|
|
|
|
|
|
|