ocarina/libsaria/collection/lens.py
Bryan Schumaker bb86a70ae4 Playlist next
The playlist will play the next visible song when the current song ends.
If we have reached the end of the list, we loop back around to the
beginning.
2010-10-20 22:18:41 -04:00

83 lines
1.6 KiB
Python

# Bryan Schumaker (10/1/2010)
import libsaria
import collection
from libsaria import data
save = data.save
load = data.load
sep = libsaria.path.sep
walk = libsaria.path.walk
join = libsaria.path.join
splitext = libsaria.path.splitext
badfiles = set()
def set_badfiles():
global badfiles
bf = load("badfiles")
if bf != None:
badfiles = bf
class Library(collection.Collection):
def __init__(self):
collection.Collection.__init__(self, "library.dl_tree")
def scan(self, path):
print "Library scanning %s" % path
set_badfiles()
self.reset()
self.update(path)
self.save()
save(badfiles, "badfiles", "")
self.disp()
def update(self, path):
global 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_allocate(split_root + [file], ref)
except UnicodeEncodeError:
pass
class Playlist(collection.Collection):
def __init__(self):
collection.Collection.__init__(self, "playlist.dl_tree")
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