2010-10-01 21:33:19 -04:00
|
|
|
# Bryan Schumaker (10/1/2010)
|
|
|
|
|
|
|
|
import libsaria
|
|
|
|
import collection
|
|
|
|
|
|
|
|
from libsaria import data
|
|
|
|
|
2010-10-10 13:45:52 -04:00
|
|
|
save = data.save
|
|
|
|
load = data.load
|
|
|
|
|
2010-10-01 21:33:19 -04:00
|
|
|
sep = libsaria.path.sep
|
|
|
|
walk = libsaria.path.walk
|
|
|
|
join = libsaria.path.join
|
|
|
|
splitext = libsaria.path.splitext
|
|
|
|
|
2010-10-10 13:45:52 -04:00
|
|
|
badfiles = set()
|
|
|
|
|
|
|
|
def set_badfiles():
|
|
|
|
global badfiles
|
|
|
|
bf = load("badfiles")
|
|
|
|
if bf != None:
|
|
|
|
badfiles = bf
|
|
|
|
|
2010-10-20 21:53:47 -04:00
|
|
|
|
2010-10-08 13:09:42 -04:00
|
|
|
class Library(collection.Collection):
|
2010-10-01 21:33:19 -04:00
|
|
|
def __init__(self):
|
2010-10-20 21:11:12 -04:00
|
|
|
collection.Collection.__init__(self, "library.dl_tree")
|
2010-10-01 21:33:19 -04:00
|
|
|
|
|
|
|
def scan(self, path):
|
|
|
|
print "Library scanning %s" % path
|
2010-10-10 13:45:52 -04:00
|
|
|
set_badfiles()
|
2010-10-01 21:33:19 -04:00
|
|
|
self.reset()
|
|
|
|
self.update(path)
|
2010-10-06 23:31:36 -04:00
|
|
|
self.save()
|
2010-10-10 13:45:52 -04:00
|
|
|
save(badfiles, "badfiles", "")
|
2010-10-01 21:33:19 -04:00
|
|
|
self.disp()
|
|
|
|
|
|
|
|
def update(self, path):
|
2010-10-10 13:45:52 -04:00
|
|
|
global badfiles
|
2010-10-01 21:33:19 -04:00
|
|
|
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:
|
2010-10-03 19:00:06 -04:00
|
|
|
self.insert_allocate(split_root + [file], ref)
|
|
|
|
except UnicodeEncodeError:
|
2010-10-01 21:33:19 -04:00
|
|
|
pass
|
2010-10-20 21:11:12 -04:00
|
|
|
|
2010-10-20 21:53:47 -04:00
|
|
|
|
|
|
|
class Playlist(collection.Collection):
|
|
|
|
def __init__(self):
|
|
|
|
collection.Collection.__init__(self, "playlist.dl_tree")
|
|
|
|
|
2010-10-20 22:18:41 -04:00
|
|
|
def next_id(self, last_id):
|
|
|
|
return_next = False
|
|
|
|
first = None
|
|
|
|
visible = self.is_visible
|
|
|
|
for id in self.walk_ids():
|
|
|
|
if visible(id):
|
|
|
|
if first == None:
|
|
|
|
first = id
|
|
|
|
if return_next == True:
|
|
|
|
return id
|
|
|
|
if id == last_id:
|
|
|
|
return_next = True
|
|
|
|
if first != None:
|
|
|
|
return first
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|