libsaria: Playlist filtering and next() fixes
I removed the old playlist filtering code, since I now have a generic way of doing this. I also fixed the next function to use the revised get_attrs() function.
This commit is contained in:
parent
bfeeb7f568
commit
de1acd8a23
|
@ -36,6 +36,9 @@ class Source:
|
|||
except:
|
||||
return False
|
||||
|
||||
def get_attrs_id(id, *attrs):
|
||||
return library.get_attrs(id, *attrs)
|
||||
|
||||
def get_attrs(*attrs):
|
||||
# I should probably get a lock here...
|
||||
if cur_id:
|
||||
|
@ -43,7 +46,8 @@ def get_attrs(*attrs):
|
|||
return -1
|
||||
|
||||
def filter(text):
|
||||
library.filter(text)
|
||||
visible = library.filter(text)
|
||||
playlist.set_visible(visible)
|
||||
callbacks.refilter()
|
||||
|
||||
def is_visible(id):
|
||||
|
@ -84,7 +88,7 @@ def next():
|
|||
id = playlist.get_next(cur_id)
|
||||
if id != None:
|
||||
cur_id = id
|
||||
return oldlibrary.get_attrs(cur_id, "filepath")
|
||||
return get_attrs("filepath")[0]
|
||||
|
||||
def list_source(list_func, *attrs):
|
||||
ret = []
|
||||
|
|
|
@ -76,3 +76,4 @@ def filter(text):
|
|||
text = unicode(text)
|
||||
terms = format(text)
|
||||
matching = do_filter(terms)
|
||||
return matching
|
||||
|
|
|
@ -5,52 +5,34 @@ from libsaria.sources import oldlibrary
|
|||
import playlist
|
||||
import next
|
||||
|
||||
filtered = False
|
||||
visible = None
|
||||
|
||||
# Function pointers for convenience
|
||||
add_ids = playlist.add_ids
|
||||
rm_ids = playlist.rm_ids
|
||||
reset = playlist.reset
|
||||
|
||||
playlist.load()
|
||||
visible = playlist.as_set()
|
||||
|
||||
def list_ids():
|
||||
for id in playlist.song_list:
|
||||
yield id
|
||||
|
||||
def filter(text):
|
||||
def set_visible(vset):
|
||||
global visible
|
||||
global filtered
|
||||
if len(text) > 0:
|
||||
visible = playlist.as_set().intersection(oldlibrary.test_filter(text))
|
||||
filtered = True
|
||||
else:
|
||||
visible = None
|
||||
filtered = False
|
||||
|
||||
def is_visible(id):
|
||||
if filtered == True:
|
||||
return id in visible
|
||||
return True
|
||||
visible = playlist.as_set().intersection(vset)
|
||||
|
||||
def num_visible():
|
||||
if filtered == True:
|
||||
return len(visible)
|
||||
return len(playlist.song_list)
|
||||
return len(visible)
|
||||
|
||||
def get_next(cur_id):
|
||||
id = None
|
||||
if libsaria.prefs.get("libsaria.random") == True:
|
||||
if filtered == False:
|
||||
index = next.rand_next(playlist.song_list)
|
||||
else:
|
||||
index = next.rand_next(list(visible))
|
||||
index = next.rand_next(list(visible))
|
||||
else:
|
||||
index = next.seq_next(cur_id)
|
||||
if index != None:
|
||||
id = playlist.get(index)
|
||||
if id != None:
|
||||
artist, title, file = oldlibrary.get_attrs(id, "artist", "title", "filepath")
|
||||
artist, title = libsaria.sources.get_attrs_id(id, "artist", "title")
|
||||
next.track_recent(artist, title)
|
||||
return id
|
||||
|
|
|
@ -19,7 +19,7 @@ def incr_index(cur_index, max_index):
|
|||
|
||||
def seq_next(cur_id):
|
||||
from libsaria import sources
|
||||
is_visible = sources.playlist.is_visible
|
||||
is_visible = sources.is_visible
|
||||
|
||||
max = playlist.size()
|
||||
if max == 0: # List is empty
|
||||
|
|
Loading…
Reference in New Issue