3 #from brisa.core.reactors import install_default_reactor
4 #reactor = install_default_reactor()
6 from brisa.core import log
7 from brisa.upnp.device import Service, ServiceController
11 class PlayListOutBoundExcept(Exception):
12 def __init__(self, *args, **kwargs):
13 Exception.__init__(self, args, kwargs)
16 class PlayList(Service):
20 Implements a playlist for ZukeBox server as a service.
21 For now the playlist works with a range of 10 positions, but in the
22 future that should change to range of undefined positions, thus
23 the playlist will be "sizeable".
26 srvc_type = "urn:schemas-upnp-org:service:PlayList:1"
27 srvc_name = "PlayList"
29 def __init__(self, positions, xml_path):
30 scpd_path = pjoin(xml_path, "zukebox-playlist-scpd.xml")
31 log.info("PlayList service scpd_path = %s" % scpd_path)
32 Service.__init__(self, self.srvc_name, self.srvc_type, '', scpd_path)
34 self.positions = positions
37 self.prev = self.current
41 self.current_uri = None
42 self.current_uri_metadata = None
46 def soap_IsLocked(self, *args, **kwargs):
47 if len(self.list) == self.positions:
49 return {"Locked": self.locked}
51 def soap_IsAvailable(self, *args, **kwargs):
52 if not len(self.list) < 10:
54 return {"Available": self.available}
56 def soap_Append(self, *args, **kwargs):
57 """Put a object in the playlist
60 self.current_uri = kwargs["CurrentURI"]
61 self.current_uri_metadata = kwargs["CurrentURIMetaData"]
62 self.from_name = kwargs["FromName"]
63 self.to_name = kwargs["ToName"]
64 req = {"cur_uri": self.current_uri,
65 "cur_uri_data": self.current_uri_metadata,
66 "from_name": self.from_name,
67 "to_name": self.to_name}
72 raise PlayListOutBoundExcept("Playlist is full")
74 def soap_Drop(self, *args, **kwargs):
75 """Pop the object at position passed by index
78 index = kwargs["Index"]
82 raise PlayListOutBoundExcept("Playlist unavailable")
84 def soap_GetSizeOfPlayList(self, *args, **kwargs):
85 """Return the size of playlist"""
86 lenght = len(self.list)
87 return {"PlayListSize": lenght}
89 def soap_GetCurrentItem(self, *args, **kwargs):
90 """Get the current position from playlist"""
92 curr = self.list[self.current]
94 curr_uri = curr["cur_uri"]
95 return {"CurrentItem": curr_uri}
97 def soap_GetNextItem(self, *args, **kwargs):
98 """Get the next item position from playlist"""
99 if self.current == len(self.list) - 1:
100 self.next = self.current
102 self.next = self.current + 1
103 self.current = self.next
104 next = self.list[self.next]
105 #for now get only next uri
106 next_uri = next["cur_uri"]
107 return {"NextItem": next_uri}
109 def soap_GetPreviousItem(self, *args, **kwargs):
110 """Get the previous item position from playlist"""
111 if self.current != 0:
112 self.prev = self.current - 1
113 self.current = self.prev
114 prev = self.list[self.prev]
115 #for now get only previous uri
116 prev_uri = prev["cur_uri"]
117 return {"PreviousItem": prev_uri}
119 def soap_GetPlaylist(self, *args, **kwargs):
120 """Get the playlist"""
121 playlist = self.list.__str__()
122 return {"Playlist": playlist}
125 def clean_playlist(self):
129 def get_playlist(self):