annotate vixm/playlist.py @ 51:8396cc3816ee pure tip

On shutdown, make sure we tell the dbus clients that we're done
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Mon, 06 Nov 2006 06:16:19 -0500
parents 3eee483b5c4e
children
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
48
3eee483b5c4e start with random song if we're supposed to randomize
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 40
diff changeset
18 self.__cursor = -1
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
19
48
3eee483b5c4e start with random song if we're supposed to randomize
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 40
diff changeset
20 def first_song(self):
3eee483b5c4e start with random song if we're supposed to randomize
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 40
diff changeset
21 self.__cursor = self.__allowrand and self.__rnd() or 0
3eee483b5c4e start with random song if we're supposed to randomize
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 40
diff changeset
22
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
23 def enqueue(self, song):
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
24 """ Append a song to the list """
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
25 self.__list.append(song)
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
26
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
27 def dequeue(self, song):
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
28 """ Remove a song from the list """
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
29 self.__list.remove(song)
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
30
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
31 def pop(self):
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
32 """ Pop the next song """
11
50584a5c300e Fixed up code to make more sense
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 9
diff changeset
33 return self.__list.pop(0)
2
80a717f97cef Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
34
39
9995931be5b1 Select first song randomly if needed
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 34
diff changeset
35 def __rnd(self):
9995931be5b1 Select first song randomly if needed
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 34
diff changeset
36 return random.randint(0, len(self.__list)-1)
9995931be5b1 Select first song randomly if needed
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 34
diff changeset
37
32
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
38 def next(self):
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
39 """ Get the next song """
33
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
40 idx = self.__cursor
32
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
41
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
42 if not self.__allowrand:
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
43 self.__cursor += 1
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
44 if self.__cursor >= len(self.__list):
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
45 self.__cursor = 0
33
99983189d4b2 Redo next song selection logic
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 32
diff changeset
46 else:
39
9995931be5b1 Select first song randomly if needed
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 34
diff changeset
47 self.__cursor = self.__rnd()
32
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
48
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
49 return self.__list[idx]
f97eb9f0c207 Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 21
diff changeset
50
3
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
51 def __getitem__(self, i):
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
52 """ 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
53 return self.__list[i]
dd00b69169c6 Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2
diff changeset
54
8
79340745c952 Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3
diff changeset
55 def __len__(self):
79340745c952 Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3
diff changeset
56 """ 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
57 return len(self.__list)
79340745c952 Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3
diff changeset
58
15
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
59 def search(self, regexp):
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
60 """ Yield all the songs matching regexp """
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
61 for song in self.__list:
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
62 if re.search(regexp, str(song), re.IGNORECASE):
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
63 yield song
ae3451bedeb6 Implemented playlist searching
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 11
diff changeset
64
9
eaa800169f5b Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 8
diff changeset
65 def index(self, song):
eaa800169f5b Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 8
diff changeset
66 """ 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
67 return self.__list.index(song)
eaa800169f5b Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 8
diff changeset
68