Random song from playlist
I can once again play random songs from the playlist.
This commit is contained in:
parent
ed2e5b882b
commit
3cb1959a7f
|
@ -47,15 +47,15 @@ def lib_get_cur_id():
|
||||||
def plist_refresh():
|
def plist_refresh():
|
||||||
return call("PLISTREFRESH")
|
return call("PLISTREFRESH")
|
||||||
|
|
||||||
def choose_next():
|
#def choose_next():
|
||||||
global playlist
|
# global playlist
|
||||||
global cur_lib_id
|
# global cur_lib_id
|
||||||
if libsaria.prefs["random"] == True:
|
# if libsaria.prefs["random"] == True:
|
||||||
next = playlist.random()
|
# next = playlist.random()
|
||||||
else:
|
# else:
|
||||||
next = playlist.next_id(cur_lib_id)
|
# next = playlist.next_id(cur_lib_id)
|
||||||
if next != None:
|
# if next != None:
|
||||||
return call("NEXT", play_id, next)
|
# return call("NEXT", play_id, next)
|
||||||
|
|
||||||
def change_score():
|
def change_score():
|
||||||
prcnt = libsaria.audio.get_progress()
|
prcnt = libsaria.audio.get_progress()
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# Bryan Schumaker (11/07/2010)
|
# Bryan Schumaker (11/07/2010)
|
||||||
|
|
||||||
|
import random as rand
|
||||||
|
|
||||||
import libsaria
|
import libsaria
|
||||||
from libsaria.collection import library
|
from libsaria.collection import library
|
||||||
call = libsaria.event.call
|
call = libsaria.event.call
|
||||||
|
@ -7,9 +9,12 @@ call = libsaria.event.call
|
||||||
song_list = None
|
song_list = None
|
||||||
song_set = None
|
song_set = None
|
||||||
|
|
||||||
filtered = False
|
filtered = False
|
||||||
visible = None
|
visible = None
|
||||||
cur_index = -1
|
recent = []
|
||||||
|
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
|
||||||
|
|
||||||
def add_id(id):
|
def add_id(id):
|
||||||
global song_list
|
global song_list
|
||||||
|
@ -59,6 +64,11 @@ def is_visible(id):
|
||||||
return id in visible
|
return id in visible
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def num_visible():
|
||||||
|
if filtered == True:
|
||||||
|
return len(visible)
|
||||||
|
return len(song_list)
|
||||||
|
|
||||||
def seq_next():
|
def seq_next():
|
||||||
global cur_index
|
global cur_index
|
||||||
global song_list
|
global song_list
|
||||||
|
@ -67,7 +77,40 @@ def seq_next():
|
||||||
cur_index += 1
|
cur_index += 1
|
||||||
return song_list[cur_index]
|
return song_list[cur_index]
|
||||||
|
|
||||||
def next():
|
def rand_candidate(max):
|
||||||
id = seq_next()
|
index = rand.randint(0, max-1)
|
||||||
return call("NEXT", library.play_id, id)
|
if filtered == False:
|
||||||
|
return song_list[index]
|
||||||
|
return list(visible)[index]
|
||||||
|
|
||||||
|
def rand_next():
|
||||||
|
n = num_visible()
|
||||||
|
if n == 0:
|
||||||
|
return
|
||||||
|
get_attrs = library.get_attrs
|
||||||
|
for i in xrange(15):
|
||||||
|
id = rand_candidate(n)
|
||||||
|
(artist, title, score) = get_attrs(id, "artist", "title", "score")
|
||||||
|
if (artist, title) in recent:
|
||||||
|
print recent_msg % (artist, title)
|
||||||
|
continue
|
||||||
|
if score < 0:
|
||||||
|
do_play = rand.randint(0, 100)
|
||||||
|
if do_play < ((20 * score) + 100):
|
||||||
|
print skip_msg % (artist, title)
|
||||||
|
continue
|
||||||
|
recent.append((artist, title))
|
||||||
|
if len(recent) > 50:
|
||||||
|
recent.pop(0)
|
||||||
|
if i > 0:
|
||||||
|
print "Picking a song took %s iterations" % i
|
||||||
|
return id
|
||||||
|
|
||||||
|
def next():
|
||||||
|
if libsaria.prefs["random"] == True:
|
||||||
|
id = rand_next()
|
||||||
|
print id, library.get_attrs(id, "filepath")
|
||||||
|
else:
|
||||||
|
id = seq_next()
|
||||||
|
if id != None:
|
||||||
|
return call("NEXT", library.play_id, id)
|
||||||
|
|
Loading…
Reference in New Issue