pjoin = os.path.join
class PlayListOutBoundExcept(Exception):
- def __rep__(self):
- return "Play List Out of Bounds!"
-
+ def __init__(self, *args, **kwargs):
+ Exception.__init__(self, args, kwargs)
class PlayList(Service):
"""Class PlayList
Introduction
============
- Implements a playlist for ZukeBox server.
+ Implements a playlist for ZukeBox server as a service.
+ For now the playlist works with a range of 10 positions, but in the
+ future that should change to range of undefined positions, thus
+ the playlist will be "sizeable".
"""
- service_type = "urn:schemas-upnp-org:service:PlayList:1"
- service_name = "PlayList"
+ srvc_type = "urn:schemas-upnp-org:service:PlayList:1"
+ srvc_name = "PlayList"
def __init__(self, positions=10, xml_path=''):
scpd_path = pjoin(xml_path, "zukebox-playlist-scpd.xml")
- Service.__init__(self, self.service_name, self.service_type, '', scpd_path,
- PlayListControl(positions, self.service_type))
-
- def get_playlist(self):
- return self.control_controller.get_playlist()
+ log.info("PlayList service scpd_path = %s" % scpd_path)
+ Service.__init__(self, self.srvc_name, self.srvc_type, '', scpd_path)
-class PlayListControl(ServiceController):
-
- def __init__(self, positions, serv_type):
- ServiceController.__init__(self, serv_type)
self.positions = positions
self.list = []
self.current = 0
self.to_name = None
self.current_uri = None
self.current_uri_metadata = None
+ self.locked = 0
+ self.available = 1
def soap_IsLocked(self, *args, **kwargs):
- locked = True
- if not len(self.list) == self.positions:
- locked = False
- rt = {"Locked": locked}
- return {"IsLockedResponse": rt}
-
- def soap_IsAvailble(self, *args, **kwargs):
- availble = False
- if not len(self.list) == 0:
- availble = True
- rt = {"Availble": availble}
- return {"IsAvailbleResponse": rt}
-
- def soap_IsAvailble(self, *args, **kwargs):
- availble = False
- if not len(self.list) == 0:
- availble = True
- rt = {"Availble": availble}
- return {"IsAvailbleResponse": rt}
+ if len(self.list) == self.positions:
+ self.locked = 1
+ return {"Locked": self.locked}
+
+ def soap_IsAvailable(self, *args, **kwargs):
+ if not len(self.list) < 10:
+ self.available = 0
+ return {"Available": self.available}
def soap_Append(self, *args, **kwargs):
"""Put a object in the playlist
"""
- if not self.is_locked():
+ if not self.locked:
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)
+ req = {"cur_uri": self.current_uri,
+ "cur_uri_data": self.current_uri_metadata,
+ "from_name": self.from_name,
+ "to_name": self.to_name}
+ self.list.append(req)
- return {"Append": {}}
+ return {}
else:
- raise PlayListOutBoundExcept()
+ raise PlayListOutBoundExcept("Playlist is full")
def soap_Drop(self, *args, **kwargs):
"""Pop the object at position passed by index
"""
- if self.is_availble():
+ if self.available:
index = kwargs["Index"]
self.list.pop(index)
- return {"Drop": {}}
+ return {}
else:
- raise PlayListOutBoundExcept()
+ raise PlayListOutBoundExcept("Playlist unavailable")
def soap_GetSizeOfPlayList(self, *args, **kwargs):
"""Return the size of playlist"""
lenght = len(self.list)
- rt = {"PlayListSize": lenght}
- return {"GetSizeOfPlayListResponse": rt}
+ return {"PlayListSize": lenght}
+
+ def soap_GetCurrentItem(self, *args, **kwargs):
+ """Get the current position from playlist"""
+ if self.available:
+ curr = self.list[self.current]
+ #for now get only uri
+ curr_uri = curr["cur_uri"]
+ return {"CurrentItem": curr_uri}
+
+ def soap_GetNextItem(self, *args, **kwargs):
+ """Get the next item position from playlist"""
+ if self.current == len(self.list) - 1:
+ self.next = self.current
+ else:
+ self.next = self.current + 1
+ self.current = self.next
+ next = self.list[self.next]
+ #for now get only next uri
+ next_uri = next["cur_uri"]
+ return {"NextItem": next_uri}
+
+ def soap_GetPreviousItem(self, *args, **kwargs):
+ """Get the previous item position from playlist"""
+ if self.current != 0:
+ self.prev = self.current - 1
+ self.current = self.prev
+ prev = self.list[self.prev]
+ #for now get only previous uri
+ prev_uri = prev["cur_uri"]
+ return {"PreviousItem": prev_uri}
+
+ def soap_GetPlaylist(self, *args, **kwargs):
+ """Get the playlist"""
+ return {"Playlist": self.list}
- def soap_GetCurrent(self, *args, **kwargs):
- if self.is_availble():
- rt = {"CurrentPosition": self.list[self.current]}
- return {"GetCurrentResponse": rt}
def clean_playlist(self):
- if self.is_availble():
+ if self.available:
self.list = []
def get_playlist(self):