Mercurial > vixm
diff vixm/playlist.py @ 32:f97eb9f0c207 master
Add random song selection for default queue
author | Josef "Jeff" Sipek <jeffpc@josefsipek.net> |
---|---|
date | Fri, 03 Nov 2006 23:26:35 -0500 |
parents | dfcf1a46fc56 |
children | 99983189d4b2 |
line wrap: on
line diff
--- a/vixm/playlist.py Fri Nov 03 23:02:15 2006 -0500 +++ b/vixm/playlist.py Fri Nov 03 23:26:35 2006 -0500 @@ -6,6 +6,7 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. +import random import xmms, re LIST_PRIO = 0 @@ -15,6 +16,7 @@ def __init__(self, allowrandom=False): self.__list = [] self.__allowrand = allowrandom # allow randomization of this list + self.__cursor = 0 def enqueue(self, song): """ Append a song to the list """ @@ -28,6 +30,19 @@ """ Pop the next song """ return self.__list.pop(0) + def next(self): + """ Get the next song """ + idx = random.randint(0, len(self.__list)-1) + + if not self.__allowrand: + idx = self.__cursor + + self.__cursor += 1 + if self.__cursor >= len(self.__list): + self.__cursor = 0 + + return self.__list[idx] + def __getitem__(self, i): """ Get item at position i """ return self.__list[i]