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():
|
||||
return call("PLISTREFRESH")
|
||||
|
||||
def choose_next():
|
||||
global playlist
|
||||
global cur_lib_id
|
||||
if libsaria.prefs["random"] == True:
|
||||
next = playlist.random()
|
||||
else:
|
||||
next = playlist.next_id(cur_lib_id)
|
||||
if next != None:
|
||||
return call("NEXT", play_id, next)
|
||||
#def choose_next():
|
||||
# global playlist
|
||||
# global cur_lib_id
|
||||
# if libsaria.prefs["random"] == True:
|
||||
# next = playlist.random()
|
||||
# else:
|
||||
# next = playlist.next_id(cur_lib_id)
|
||||
# if next != None:
|
||||
# return call("NEXT", play_id, next)
|
||||
|
||||
def change_score():
|
||||
prcnt = libsaria.audio.get_progress()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# Bryan Schumaker (11/07/2010)
|
||||
|
||||
import random as rand
|
||||
|
||||
import libsaria
|
||||
from libsaria.collection import library
|
||||
call = libsaria.event.call
|
||||
|
@ -7,9 +9,12 @@ call = libsaria.event.call
|
|||
song_list = None
|
||||
song_set = None
|
||||
|
||||
filtered = False
|
||||
visible = None
|
||||
cur_index = -1
|
||||
filtered = False
|
||||
visible = None
|
||||
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):
|
||||
global song_list
|
||||
|
@ -59,6 +64,11 @@ def is_visible(id):
|
|||
return id in visible
|
||||
return True
|
||||
|
||||
def num_visible():
|
||||
if filtered == True:
|
||||
return len(visible)
|
||||
return len(song_list)
|
||||
|
||||
def seq_next():
|
||||
global cur_index
|
||||
global song_list
|
||||
|
@ -67,7 +77,40 @@ def seq_next():
|
|||
cur_index += 1
|
||||
return song_list[cur_index]
|
||||
|
||||
def next():
|
||||
id = seq_next()
|
||||
return call("NEXT", library.play_id, id)
|
||||
def rand_candidate(max):
|
||||
index = rand.randint(0, max-1)
|
||||
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