Playlist random improvements

I now keep track of the last 15 songs played.  If a song with the same
(artist, title) as one of the songs in the list attempts to play, we
skip it.

Songs with a negative score have a (20 * score) + 100 per cent chance of
playing.  When score is -5, the song should never play.

I used to try to find a song 5 times before giving up and playing the
song with the current id.  I have upped the threshold to 15.
This commit is contained in:
Bryan Schumaker 2010-10-25 20:33:22 -04:00
parent 43eab40b01
commit c35f210369
1 changed files with 20 additions and 6 deletions

View File

@ -73,6 +73,7 @@ class Library(collection.Collection):
class Playlist(collection.Collection):
def __init__(self):
collection.Collection.__init__(self, "playlist.dl_tree")
self.last_tracks = []
def next_id(self, last_id):
return_next = False
@ -94,13 +95,26 @@ class Playlist(collection.Collection):
if self.size == 0:
return
getattr = libsaria.collection.lib_get_attr
for i in xrange(5):
last = self.last_tracks
for i in xrange(15):
id = self.get_rand_candidate()
if getattr(id, "score") >= 0:
return id
play_anyway = rand.randint(0, 1)
if play_anyway == 1:
return id
artist = getattr(id, "artist")
album = getattr(id, "album")
title = getattr(id, "title")
if (artist, title) in last:
print "Skipping %s by %s because it has played recently." % (title, artist)
continue
score = getattr(id, "score")
if score < 0:
play_anyway = rand.randint(0, 100)
if play_anyway < ((20 * score) + 100):
print "Skipping %s by %s because I don't think you want to hear it." % (title, artist)
continue
last.append((artist, title))
if len(last) > 15:
last.pop(0)
print "Picking a song took %s iterations" % i
return id
return id
def get_rand_candidate(self):