Added the files zukebox_playlist and seeker.py
[zukebox] / zukebox_server / src / playlist / zukebox_playlist.py
diff --git a/zukebox_server/src/playlist/zukebox_playlist.py b/zukebox_server/src/playlist/zukebox_playlist.py
new file mode 100644 (file)
index 0000000..3e2683f
--- /dev/null
@@ -0,0 +1,66 @@
+
+import dbus.service
+
+from brisa.core import log
+
+class PlayListOutBoundExcept(Exception):
+    def __rep__(self):
+        return "Play List Out of Bounds!"
+
+
+class PlayList(list, dbus.service.Object):
+    """Class PlayList
+    Introduction
+    ============
+    Implements a playlist for ZukeBox server.
+    """
+
+    DBUS_SERVICE_NAME = "br.org.zagaia.PlayList"
+    DBUS_OBJ_PATH = "br/org/zagaia/playlist"
+    DBUS_IFACE = "br.org.zagaia.PlayList"
+
+    def __init__(self, name="", positions=10):
+        self.name = name
+        self.positions = positions
+        # when we create a playlist the current position is first
+        self.current = 0
+
+    def is_locked(self):
+        if not len(self) == self.positions:
+            return False
+        return True
+
+    def is_availble(self):
+        if not len(self) == 0:
+            return True
+        return False
+
+    @dbu.service.method(DBUS_IFACE)
+    def append(self, obj):
+        """Put a object in the playlist"""
+        if not self.is_locked():
+            log.info("object in playlist")
+            self.append(obj)
+        else:
+            raise PlayListOutBoundExcept()
+
+    @dbus.service.method(DBUS_IFACE)
+    def drop(self, index):
+        """Pop the object at position passed by index
+        @param index
+        @type integer
+        """
+        if self.is_availble():
+            self.pop(index)
+
+    @dbus.service.method(DBUS_IFACE)
+    def get_size(self):
+        """Return the size of playlist"""
+        return len(self)
+
+    @dbus.service.method(DBUS_IFACE)
+    def clean_playlist(self):
+        if self.is_availble():
+            while len(self) != 0:
+                self.pop()
+