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 #list = [{'CurrentURI':'teste', 'CurrenteURIMetaData':'teste', 'FromName':'teste', 'ToName':'teste'},
30 # {'CurrentURI':'teste', 'CurrenteURIMetaData':'teste', 'FromName':'teste', 'ToName':'teste'}]
32 def __init__(self, positions, xml_path):
33 scpd_path = pjoin(xml_path, "zukebox-playlist-scpd.xml")
34 log.info("PlayList service scpd_path = %s" % scpd_path)
35 Service.__init__(self, self.srvc_name, self.srvc_type, '', scpd_path)
37 self.positions = positions
40 self.prev = self.current
44 self.current_uri = None
45 self.current_uri_metadata = None
49 def soap_IsLocked(self, *args, **kwargs):
50 if len(self.list) == self.positions:
52 return {"Locked": self.locked}
54 def soap_IsAvailable(self, *args, **kwargs):
55 if not len(self.list) < 10:
57 return {"Available": self.available}
59 def soap_Append(self, *args, **kwargs):
60 """Put a object in the playlist
63 self.current_uri = kwargs["CurrentURI"]
64 self.current_uri_metadata = kwargs["CurrentURIMetaData"]
65 self.from_name = kwargs["FromName"]
66 self.to_name = kwargs["ToName"]
67 req = {"cur_uri": self.current_uri,
68 "cur_uri_data": self.current_uri_metadata,
69 "from_name": self.from_name,
70 "to_name": self.to_name}
75 raise PlayListOutBoundExcept("Playlist is full")
77 def soap_Drop(self, *args, **kwargs):
78 """Pop the object at position passed by index
81 index = kwargs["Index"]
85 raise PlayListOutBoundExcept("Playlist unavailable")
87 def soap_GetSizeOfPlayList(self, *args, **kwargs):
88 """Return the size of playlist"""
89 lenght = len(self.list)
90 return {"PlayListSize": lenght}
92 def soap_GetCurrentItem(self, *args, **kwargs):
93 """Get the current position from playlist"""
95 curr = self.list[self.current]
97 curr_uri = curr["cur_uri"]
98 return {"CurrentItem": curr_uri}
100 def soap_GetNextItem(self, *args, **kwargs):
101 """Get the next item position from playlist"""
102 if self.current == len(self.list) - 1:
103 self.next = self.current
105 self.next = self.current + 1
106 self.current = self.next
107 next = self.list[self.next]
108 #for now get only next uri
109 next_uri = next["cur_uri"]
110 return {"NextItem": next_uri}
112 def soap_GetPreviousItem(self, *args, **kwargs):
113 """Get the previous item position from playlist"""
114 if self.current != 0:
115 self.prev = self.current - 1
116 self.current = self.prev
117 prev = self.list[self.prev]
118 #for now get only previous uri
119 prev_uri = prev["cur_uri"]
120 return {"PreviousItem": prev_uri}
122 def soap_GetPlayList(self, *args, **kwargs):
123 """Get the playlist"""
124 playlist = str(self.get_playlist())
125 return {"PlayList": playlist}
128 def clean_playlist(self):
132 def get_playlist(self):