comparison src/plugins/plugin_misc_radiocol.py @ 827:215a2cb15e2d

plugin radiocol: sync data includes a "jump to time" info
author souliane <souliane@mailoo.org>
date Thu, 16 Jan 2014 11:44:14 +0100
parents 71f8e996f765
children 8f335c03eebb
comparison
equal deleted inserted replaced
826:71f8e996f765 827:215a2cb15e2d
61 61
62 def __init__(self, host): 62 def __init__(self, host):
63 info(_("Radio collective initialization")) 63 info(_("Radio collective initialization"))
64 self.inheritFromRoomGame(host) 64 self.inheritFromRoomGame(host)
65 RoomGame._init_(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG), 65 RoomGame._init_(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG),
66 game_init={'queue': [], 'upload': True, 'playing': False, 'to_delete': {}}) 66 game_init={'queue': [], 'upload': True, 'playing': None, 'playing_time': 0, 'to_delete': {}})
67 self.host = host 67 self.host = host
68 host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom) 68 host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom)
69 host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame) 69 host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame)
70 host.bridge.addMethod("radiocolSongAdded", ".plugin", in_sign='sss', out_sign='', method=self.radiocolSongAdded, async=True) 70 host.bridge.addMethod("radiocolSongAdded", ".plugin", in_sign='sss', out_sign='', method=self.radiocolSongAdded, async=True)
71 host.bridge.addSignal("radiocolPlayers", ".plugin", signature='ssass') # room_jid, referee, players, profile 71 host.bridge.addSignal("radiocolPlayers", ".plugin", signature='ssass') # room_jid, referee, players, profile
133 self.deleteFile(filename, radio_data) 133 self.deleteFile(filename, radio_data)
134 radio_data['to_delete'] = {} 134 radio_data['to_delete'] = {}
135 queue = radio_data['queue'] 135 queue = radio_data['queue']
136 if not queue: 136 if not queue:
137 #nothing left to play, we need to wait for uploads 137 #nothing left to play, we need to wait for uploads
138 radio_data['playing'] = False 138 radio_data['playing'] = None
139 return 139 return
140 song = queue.pop(0) 140 song = queue.pop(0)
141 filename, length = song['filename'], float(song['length']) 141 filename, length = song['filename'], float(song['length'])
142 self.send(room_jid, ('', 'play'), {'filename': filename}, profile=profile) 142 self.send(room_jid, ('', 'play'), {'filename': filename}, profile=profile)
143 radio_data['playing'] = song
144 radio_data['playing_time'] = time.time()
143 145
144 if not radio_data['upload'] and len(queue) < QUEUE_LIMIT: 146 if not radio_data['upload'] and len(queue) < QUEUE_LIMIT:
145 #upload is blocked and we now have resources to get more, we reactivate it 147 #upload is blocked and we now have resources to get more, we reactivate it
146 self.send(room_jid, ('', 'upload_ok'), profile=profile) 148 self.send(room_jid, ('', 'upload_ok'), profile=profile)
147 radio_data['upload'] = True 149 radio_data['upload'] = True
227 229
228 self.send(room_jid, preload_elt, profile=profile) 230 self.send(room_jid, preload_elt, profile=profile)
229 if not radio_data['playing'] and len(queue) == QUEUE_TO_START: 231 if not radio_data['playing'] and len(queue) == QUEUE_TO_START:
230 # We have not started playing yet, and we have QUEUE_TO_START 232 # We have not started playing yet, and we have QUEUE_TO_START
231 # songs in queue. We can now start the party :) 233 # songs in queue. We can now start the party :)
232 radio_data['playing'] = True
233 self.playNext(room_jid, profile) 234 self.playNext(room_jid, profile)
234 else: 235 else:
235 error(_('Unmanaged game element: %s') % elt.name) 236 error(_('Unmanaged game element: %s') % elt.name)
236 237
237 def getSyncData(self, room_jid_s, force_nicks=[]): 238 def getSyncData(self, room_jid_s, force_nicks=[]):
238 data = {} 239 data = {}
239 status = self.games[room_jid_s]['status'] 240 game_data = self.games[room_jid_s]
241 status = game_data['status']
240 nicks = [nick for nick in status if status[nick] == 'desync'] 242 nicks = [nick for nick in status if status[nick] == 'desync']
241 for nick in force_nicks: 243 for nick in force_nicks:
242 if nick not in nicks: 244 if nick not in nicks:
243 nicks.append(nick) 245 nicks.append(nick)
244 for nick in nicks: 246 for nick in nicks:
245 if len(self.games[room_jid_s]['queue']) > 0: 247 elements = []
246 data[nick] = copy.deepcopy(self.games[room_jid_s]['queue']) 248 if game_data['playing']:
247 if len(self.games[room_jid_s]['queue']) == QUEUE_LIMIT: 249 preload = copy.deepcopy(game_data['playing'])
248 data[nick].append(domish.Element(('', 'no_upload'))) 250 preload['filename'] += '#t=%.2f' % (time.time() - game_data['playing_time'])
251 elements.append(preload)
252 play = domish.Element(('', 'play'))
253 play['filename'] = preload['filename']
254 elements.append(play)
255 if len(game_data['queue']) > 0:
256 elements.extend(copy.deepcopy(game_data['queue']))
257 if len(game_data['queue']) == QUEUE_LIMIT:
258 elements.append(domish.Element(('', 'no_upload')))
259 if data:
260 data[nick] = elements
249 return data 261 return data