--- /dev/null
+
+class Seeker(object):
+ """This class implements a pointer for ZukeBox playlist
+ A seeker response to a request about the current position, next
+ or previous.
+ """
+ def __init__(self, playlist):
+ if playlist is not None:
+ self.playlist = playlist
+ # the first time the previous position is the current
+ self.current = playlist.current
+ self.previous = self.current
+ self.next = None
+
+ def get_next_pos(self):
+ next = self.current + 1
+ self.next = next
+
+ def get_previous_pos(self):
+ prev = self.previous
+ if prev != 0:
+ prev = prev - 1
+ self.previous = prev
+
+ def get_next(self):
+ self.get_next_pos()
+ return self.playlist.pop(self.next)
+
+ def get_prev(self):
+ self.get_previous_pos()
+ return self.playlist.pop(self.previous)
+
-import dbus.service
+import os
from brisa.core import log
+from brisa.upnp.device import Service, ServiceController
-class PlayList(list, dbus.service.Object):
+pjoin = os.path.join
+
+class PlayListOutBoundExcept(Exception):
+ def __rep__(self):
+ return "Play List Out of Bounds!"
+
+
+
+class PlayList(Service):
"""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"
+ service_type = "urn:schemas-upnp-org:service:PlayList:1"
+ service_name = "PlayList"
+
+ def __init__(self, positions=10, xml_path):
+ scpd_path = pjoin(xml_path, "zukebox-playlist-scpd.xml")
+ Service.__init__(self, service_name, service_type, '', scpd_path,
+ PlayListControl(positions, service_type))
- def __init__(self, name="", positions=10):
- self.name = name
+ def get_playlist(self):
+ return self.control_controller.get_playlist()
+
+class PlayListControl(ServiceController):
+
+ def __init__(self, positions, serv_type):
+ ServiceController.__init__(self, serv_type)
self.positions = positions
+ self.list = []
+ self.current = 0
+ self.prev = self.current
+ self.next = None
+ self.from_name = None
+ self.to_name = None
+ self.current_uri = None
+ self.current_uri_metadata = None
- def is_locked(self):
- if not len(self) == self.positions:
- return False
- return True
+ def soap_IsLocked(self, *args, **kwargs):
+ locked = True
+ if not len(self.list) == self.positions:
+ locked = False
+ rt = {"Locked": locked}
+ return {"IsLockedResponse": rt}
- def is_availble(self):
- if not len(self) == 0:
- return True
- return False
+ def soap_IsAvailble(self, *args, **kwargs):
+ availble = False
+ if not len(self.list) == 0:
+ availble = True
+ rt = {"Availble": availble}
+ return {"IsAvailbleResponse": rt}
- @dbus.service.method(DBUS_IFACE)
- def append(self, obj):
- """Put a object in the playlist"""
+ def soap_Append(self, *args, **kwargs):
+ """Put a object in the playlist
+ """
if not self.is_locked():
- log.info("object in playlist")
- self.append(obj)
+ self.current_uri = kwargs["CurrentURI"]
+ self.current_uri_metadata = kwargs["CurrentURIMetaData"]
+ self.from_name = kwargs["FromName"]
+ self.to_name = kwargs["ToName"]
+ self.list.append(self.current_uri)
- @dbus.service.method(DBUS_IFACE)
- def drop(self):
- """Always pop the first object from list"""
+ return {"Append": {}}
+ else:
+ raise PlayListOutBoundExcept()
+
+ def soap_Drop(self, *args, **kwargs):
+ """Pop the object at position passed by index
+ """
if self.is_availble():
- self.pop(0)
+ index = kwargs["Index"]
+ self.list.pop(index)
+ return {"Drop": {}}
+ else:
+ raise PlayListOutBoundExcept()
- @dbus.service.method(DBUS_IFACE)
- def get_size(self):
- """Return the current size of playlist"""
- return len(self)
+ def soap_GetSizeOfPlayList(self, *args, **kwargs):
+ """Return the size of playlist"""
+ lenght = len(self.list)
+ rt = {"PlayListSize": lenght}
+ return {"GetSizeOfPlayListResponse": rt}
- @dbus.service.method(DBUS_IFACE)
- def previous(self):
+ def soap_GetCurrent(self, *args, **kwargs):
if self.is_availble():
- pass
+ rt = {"CurrentPosition": self.list[self.current]}
+ return {"GetCurrentResponse": rt}
+ def clean_playlist(self):
+ if self.is_availble():
+ self.list = []
+ def get_playlist(self):
+ return self.list