Playlist track cur_index
We should track the current song index between sessions. This means we need to set it when selecting a random song. This also means we need to save the playlist on each song selection.
This commit is contained in:
parent
d033c25655
commit
3365f19d69
|
@ -16,7 +16,7 @@ visible = None
|
|||
recent = None
|
||||
recent_msg = "Skipping %s by %s because it has played recently"
|
||||
skip_msg = "Skipping %s by %s because I don't think you like it"
|
||||
cur_index = -1
|
||||
cur_index = None
|
||||
|
||||
def add_id(id):
|
||||
global song_list
|
||||
|
@ -33,22 +33,27 @@ def reset():
|
|||
global song_list
|
||||
global song_set
|
||||
global recent
|
||||
global cur_index
|
||||
recent = []
|
||||
song_list = []
|
||||
song_set = set()
|
||||
cur_index = -1
|
||||
|
||||
def load():
|
||||
global song_list
|
||||
global song_set
|
||||
global recent
|
||||
global visible
|
||||
global cur_index
|
||||
objects = libsaria.path.files.load("playlist", ".list")
|
||||
if objects == None or len(objects) != 2:
|
||||
if objects == None or len(objects) != 3:
|
||||
reset()
|
||||
else:
|
||||
song_list = objects[0]
|
||||
recent = objects[1]
|
||||
cur_index = objects[2]
|
||||
song_set = set(song_list)
|
||||
libsaria.sources.cur_lib_id = song_list[cur_index]
|
||||
|
||||
def load_bg2(callback):
|
||||
load()
|
||||
|
@ -61,7 +66,7 @@ def load_bg(callback):
|
|||
thr.start()
|
||||
|
||||
def save():
|
||||
libsaria.path.files.save( (song_list, recent), "playlist", ".list")
|
||||
libsaria.path.files.save( (song_list, recent, cur_index), "playlist", ".list")
|
||||
|
||||
def walk():
|
||||
global song_list
|
||||
|
@ -95,15 +100,21 @@ def seq_next():
|
|||
global cur_index
|
||||
global song_list
|
||||
cur_index += 1
|
||||
max_index = len(song_list)
|
||||
if cur_index == max_index:
|
||||
cur_index = 0
|
||||
while is_visible(song_list[cur_index]) == False:
|
||||
cur_index += 1
|
||||
if cur_index == max_index:
|
||||
cur_index = 0
|
||||
return song_list[cur_index]
|
||||
|
||||
def rand_candidate(list, max):
|
||||
index = rand.randint(0, max-1)
|
||||
return list[index]
|
||||
return list[index], index
|
||||
|
||||
def rand_next():
|
||||
global cur_index
|
||||
n = num_visible()
|
||||
if n == 0:
|
||||
return
|
||||
|
@ -115,7 +126,7 @@ def rand_next():
|
|||
selection = list(visible)
|
||||
|
||||
for i in xrange(15):
|
||||
id = rand_candidate(selection, n)
|
||||
id, index = rand_candidate(selection, n)
|
||||
(artist, title, score) = get_attrs(id, "artist", "title", "score")
|
||||
if (artist, title) in recent:
|
||||
print recent_msg % (artist, title)
|
||||
|
@ -130,12 +141,23 @@ def rand_next():
|
|||
recent.pop(0)
|
||||
if i > 0:
|
||||
print "Picking a song took %s iterations" % i
|
||||
cur_index = index
|
||||
return id
|
||||
|
||||
def play_id(id):
|
||||
global cur_index
|
||||
cur_index = song_list.index(id)
|
||||
library.play_id(id)
|
||||
save()
|
||||
|
||||
def next():
|
||||
id = None
|
||||
if len(song_list) == 0:
|
||||
return
|
||||
if libsaria.prefs.get_pref("libsaria.random") == True:
|
||||
id = rand_next()
|
||||
else:
|
||||
id = seq_next()
|
||||
if id != None:
|
||||
save()
|
||||
return call("NEXT", library.play_id, id)
|
||||
|
|
Loading…
Reference in New Issue