libsaria: New sequential next function for playlist
The new function exists in its own file to keep things simpler. Based on the current song id, it finds the index in the playlist and returns the next visible song.
This commit is contained in:
parent
0a1160f618
commit
a3af3d053d
|
@ -63,9 +63,10 @@ def play_id(id):
|
|||
|
||||
def next():
|
||||
global cur_id
|
||||
cur_id = queue.next()
|
||||
if cur_id == None:
|
||||
cur_id = playlist.get_next(cur_id)
|
||||
id = queue.next()
|
||||
if id == None:
|
||||
id = playlist.get_next(cur_id)
|
||||
cur_id = id
|
||||
return library.get_attrs(cur_id, "filepath")
|
||||
|
||||
def list_source(source, *attrs):
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import libsaria
|
||||
from libsaria.sources import library
|
||||
import playlist
|
||||
import next
|
||||
import random
|
||||
|
||||
filtered = False
|
||||
|
@ -49,18 +50,6 @@ def num_visible():
|
|||
def get_cur_id():
|
||||
return playlist.song_list[cur_index]
|
||||
|
||||
def seq_next():
|
||||
global cur_index
|
||||
cur_index += 1
|
||||
max_index = len(playlist.song_list)
|
||||
if cur_index == max_index:
|
||||
cur_index = 0
|
||||
while is_visible(playlist.song_list[cur_index]) == False:
|
||||
cur_index += 1
|
||||
if cur_index == max_index:
|
||||
cur_index = 0
|
||||
return playlist.song_list[cur_index]
|
||||
|
||||
def rand_candidate(list, max):
|
||||
index = random.randint(0, max-1)
|
||||
return list[index]
|
||||
|
@ -113,7 +102,8 @@ def get_next(cur_id):
|
|||
if libsaria.prefs.get("libsaria.random") == True:
|
||||
id = rand_next()
|
||||
else:
|
||||
id = seq_next()
|
||||
index = next.seq_next(cur_id)
|
||||
id = playlist.get(index)
|
||||
if id != None:
|
||||
artist, title, file = library.get_attrs(id, "artist", "title", "filepath")
|
||||
recent.append((artist, title))
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# Bryan Schumaker (5 / 14 / 2011)
|
||||
|
||||
import playlist
|
||||
|
||||
def incr_index(cur_index, max_index):
|
||||
cur_index += 1
|
||||
if cur_index == max_index:
|
||||
cur_index = 0
|
||||
return cur_index
|
||||
|
||||
def seq_next(cur_id):
|
||||
from libsaria import sources
|
||||
is_visible = sources.playlist.is_visible
|
||||
|
||||
index = playlist.index(cur_id)
|
||||
max = playlist.size()
|
||||
index = incr_index(index, max)
|
||||
while not is_visible(playlist.get(index)):
|
||||
index = incr_index(index, max)
|
||||
return index
|
|
@ -49,3 +49,27 @@ def as_set():
|
|||
song_set = set(song_list)
|
||||
unlock_plist()
|
||||
return song_set
|
||||
|
||||
def size():
|
||||
lock_plist()
|
||||
sz = len(song_list)
|
||||
unlock_plist()
|
||||
return sz
|
||||
|
||||
def index(item):
|
||||
lock_plist()
|
||||
try:
|
||||
idx = song_list.index(item)
|
||||
except:
|
||||
idx = -1
|
||||
unlock_plist()
|
||||
return idx
|
||||
|
||||
def get(index):
|
||||
lock_plist()
|
||||
try:
|
||||
item = song_list[index]
|
||||
except:
|
||||
item = None
|
||||
unlock_plist()
|
||||
return item
|
||||
|
|
Loading…
Reference in New Issue