changeset 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
files src/plugins/plugin_misc_radiocol.py
diffstat 1 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_radiocol.py	Wed Jan 15 23:09:39 2014 +0100
+++ b/src/plugins/plugin_misc_radiocol.py	Thu Jan 16 11:44:14 2014 +0100
@@ -63,7 +63,7 @@
         info(_("Radio collective initialization"))
         self.inheritFromRoomGame(host)
         RoomGame._init_(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG),
-                          game_init={'queue': [], 'upload': True, 'playing': False, 'to_delete': {}})
+                          game_init={'queue': [], 'upload': True, 'playing': None, 'playing_time': 0, 'to_delete': {}})
         self.host = host
         host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom)
         host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame)
@@ -135,11 +135,13 @@
         queue = radio_data['queue']
         if not queue:
             #nothing left to play, we need to wait for uploads
-            radio_data['playing'] = False
+            radio_data['playing'] = None
             return
         song = queue.pop(0)
         filename, length = song['filename'], float(song['length'])
         self.send(room_jid, ('', 'play'), {'filename': filename}, profile=profile)
+        radio_data['playing'] = song
+        radio_data['playing_time'] = time.time()
 
         if not radio_data['upload'] and len(queue) < QUEUE_LIMIT:
             #upload is blocked and we now have resources to get more, we reactivate it
@@ -229,21 +231,31 @@
                 if not radio_data['playing'] and len(queue) == QUEUE_TO_START:
                     # We have not started playing yet, and we have QUEUE_TO_START
                     # songs in queue. We can now start the party :)
-                    radio_data['playing'] = True
                     self.playNext(room_jid, profile)
             else:
                 error(_('Unmanaged game element: %s') % elt.name)
 
     def getSyncData(self, room_jid_s, force_nicks=[]):
         data = {}
-        status = self.games[room_jid_s]['status']
+        game_data = self.games[room_jid_s]
+        status = game_data['status']
         nicks = [nick for nick in status if status[nick] == 'desync']
         for nick in force_nicks:
             if nick not in nicks:
                 nicks.append(nick)
         for nick in nicks:
-            if len(self.games[room_jid_s]['queue']) > 0:
-                data[nick] = copy.deepcopy(self.games[room_jid_s]['queue'])
-                if len(self.games[room_jid_s]['queue']) == QUEUE_LIMIT:
-                    data[nick].append(domish.Element(('', 'no_upload')))
+            elements = []
+            if game_data['playing']:
+                preload = copy.deepcopy(game_data['playing'])
+                preload['filename'] += '#t=%.2f' % (time.time() - game_data['playing_time'])
+                elements.append(preload)
+                play = domish.Element(('', 'play'))
+                play['filename'] = preload['filename']
+                elements.append(play)
+            if len(game_data['queue']) > 0:
+                elements.extend(copy.deepcopy(game_data['queue']))
+                if len(game_data['queue']) == QUEUE_LIMIT:
+                    elements.append(domish.Element(('', 'no_upload')))
+            if data:
+                data[nick] = elements
         return data