56d3403f0c104bea5cace892517ba21457389947
[zukebox] / zukebox_server / src / playlist / seeker.py
1
2 class Seeker(object):
3     """This class implements a pointer for ZukeBox playlist
4     A seeker response to a request about the current position, next
5     or previous.
6     """
7     def __init__(self, playlist):
8         if playlist is not None:
9             self.playlist = playlist
10             # the first time the previous position is the current
11             self.current = playlist.current
12             self.previous = self.current
13             self.next = None
14
15     def get_next_pos(self):
16         next = self.current + 1
17         self.next = next
18
19     def get_previous_pos(self):
20         prev = self.previous
21         if prev != 0:
22             prev = prev - 1
23             self.previous = prev
24
25     def get_next(self):
26         self.get_next_pos()
27         return self.playlist.pop(self.next)
28
29     def get_prev(self):
30         self.get_previous_pos()
31         return self.playlist.pop(self.previous)
32