annotate vixm/playlist.py @ 34:8028f2addb00 master

Destroy all traces of xmms
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Fri, 03 Nov 2006 23:34:59 -0500
parents 99983189d4b2
children 9995931be5b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 15
diff changeset
1 # playlist.py - playlist interface
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 15
diff changeset
2 #
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 15
diff changeset
3 # Copyright (C) 2006 Josef "Jeff" Sipek <jeffpc@josefsipek.net>
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 15
diff changeset
4 #
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 15
diff changeset
5 # This program is free software; you can redistribute it and/or modify
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 15
diff changeset
6 # it under the terms of the GNU General Public License version 2 as
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 15
diff changeset
7 # published by the Free Software Foundation.
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
8
34
8028f2addb00 Destroy all traces of xmms
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 33
diff changeset
9 import random, re
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
10
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
11 LIST_PRIO = 0
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
12 LIST_DEFAULT = 1
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
13
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
14 class playlist:
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
15 def __init__(self, allowrandom=False):
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
16 self.__list = []
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
17 self.__allowrand = allowrandom # allow randomization of this list
32
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
18 self.__cursor = 0
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
19
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
20 def enqueue(self, song):
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
21 """ Append a song to the list """
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
22 self.__list.append(song)
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
23
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
24 def dequeue(self, song):
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
25 """ Remove a song from the list """
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
26 self.__list.remove(song)
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
27
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
28 def pop(self):
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
29 """ Pop the next song """
11
50584a5c300e Fixed up code to make more sense
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 9
diff changeset
30 return self.__list.pop(0)
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
31
32
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
32 def next(self):
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
33 """ Get the next song """
33
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
34 def rnd():
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
35 return random.randint(0, len(self.__list)-1)
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
36
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
37 ##
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
38
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
39 idx = self.__cursor
32
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
40
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
41 if not self.__allowrand:
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
42 self.__cursor += 1
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
43 if self.__cursor >= len(self.__list):
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
44 self.__cursor = 0
33
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
45 else:
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
46 self.__cursor = rnd()
32
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
47
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
48 return self.__list[idx]
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
49
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
50 def __getitem__(self, i):
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
51 """ Get item at position i """
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
52 return self.__list[i]
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
53
8
79340745c952 Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3
diff changeset
54 def __len__(self):
79340745c952 Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3
diff changeset
55 """ Return the length of the playlist """
79340745c952 Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3
diff changeset
56 return len(self.__list)
79340745c952 Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3
diff changeset
57
15
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
58 def search(self, regexp):
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
59 """ Yield all the songs matching regexp """
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
60 for song in self.__list:
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
61 if re.search(regexp, str(song), re.IGNORECASE):
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
62 yield song
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
63
9
eaa800169f5b Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 8
diff changeset
64 def index(self, song):
eaa800169f5b Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 8
diff changeset
65 """ Returns the index of the first occurence of song """
eaa800169f5b Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 8
diff changeset
66 return self.__list.index(song)
eaa800169f5b Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 8
diff changeset
67