annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for managing Radiocol
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 790
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 765
diff changeset
20 from sat.core.i18n import _
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from logging import debug, info, warning, error
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.words.xish import domish
577
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
23 from twisted.internet import reactor
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
24 from twisted.words.protocols.jabber import jid
765
787ee59dba9c plugins radiocol, xep-0054: better handling of upload errors:
souliane <souliane@mailoo.org>
parents: 764
diff changeset
25 from twisted.internet import threads, defer
787ee59dba9c plugins radiocol, xep-0054: better handling of upload errors:
souliane <souliane@mailoo.org>
parents: 764
diff changeset
26 from sat.core import exceptions
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
27 import os.path
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
28 import copy
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
29 import time
577
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
30 from os import unlink
464
794f60e2da27 plugin radiocol: fixed missing import
Goffi <goffi@goffi.org>
parents: 459
diff changeset
31 from mutagen.oggvorbis import OggVorbis, OggVorbisHeaderError
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
33
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 NC_RADIOCOL = 'http://www.goffi.org/protocol/radiocol'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 RADIOC_TAG = 'radiocol'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
38 "name": "Radio collective plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
39 "import_name": "Radiocol",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
40 "type": "Exp",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
41 "protocols": [],
718
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
42 "dependencies": ["XEP-0045", "XEP-0249", "ROOM-GAME"],
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
43 "main": "Radiocol",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
44 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
45 "description": _("""Implementation of radio collective""")
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 }
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
48
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
49 # Number of songs needed in the queue before we start playing
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
50 QUEUE_TO_START = 2
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
51 # Maximum number of songs in the queue (the song being currently played doesn't count)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
52 QUEUE_LIMIT = 2
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
53
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
718
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
55 class Radiocol(object):
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
56
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
57 def inheritFromRoomGame(self, host):
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
58 global RoomGame
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
59 RoomGame = host.plugins["ROOM-GAME"].__class__
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
60 self.__class__ = type(self.__class__.__name__, (self.__class__, RoomGame, object), {})
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def __init__(self, host):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 info(_("Radio collective initialization"))
718
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
64 self.inheritFromRoomGame(host)
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
65 RoomGame._init_(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG),
827
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
66 game_init={'queue': [], 'upload': True, 'playing': None, 'playing_time': 0, 'to_delete': {}})
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self.host = host
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 683
diff changeset
68 host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom)
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
69 host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame)
765
787ee59dba9c plugins radiocol, xep-0054: better handling of upload errors:
souliane <souliane@mailoo.org>
parents: 764
diff changeset
70 host.bridge.addMethod("radiocolSongAdded", ".plugin", in_sign='sss', out_sign='', method=self.radiocolSongAdded, async=True)
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
71 host.bridge.addSignal("radiocolPlayers", ".plugin", signature='ssass') # room_jid, referee, players, profile
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
72 host.bridge.addSignal("radiocolStarted", ".plugin", signature='ssasais') # room_jid, referee, players, [QUEUE_TO_START, QUEUE_LIMIT], profile
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
73 host.bridge.addSignal("radiocolSongRejected", ".plugin", signature='sss') # room_jid, reason, profile
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
74 host.bridge.addSignal("radiocolPreload", ".plugin", signature='sssssss') # room_jid, timestamp, filename, title, artist, album, profile
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
75 host.bridge.addSignal("radiocolPlay", ".plugin", signature='sss') # room_jid, filename, profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
76 host.bridge.addSignal("radiocolNoUpload", ".plugin", signature='ss') # room_jid, profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
77 host.bridge.addSignal("radiocolUploadOk", ".plugin", signature='ss') # room_jid, profile
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
79 def __create_preload_elt(self, sender, song_added_elt):
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
80 preload_elt = copy.deepcopy(song_added_elt)
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
81 preload_elt.name = 'preload'
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
82 preload_elt['sender'] = sender
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
83 preload_elt['timestamp'] = str(time.time())
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
84 # attributes filename, title, artist, album, length have been copied
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
85 # XXX: the frontend should know the temporary directory where file is put
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
86 return preload_elt
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
87
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
88 def radiocolSongAdded(self, referee, song_path, profile):
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
89 """This method is called by libervia when a song has been uploaded
790
19262fb77230 plugin room game: improved docstrings, added '_' as prefix for internal methods names
souliane <souliane@mailoo.org>
parents: 771
diff changeset
90 @param referee: JID of the referee in the room (room userhost + '/' + nick)
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
91 @song_path: absolute path of the song added
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
92 @param profile_key: %(doc_profile_key)s"""
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
93 #XXX: this is a Q&D way for the proof of concept. In the future, the song should
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
94 # be streamed to the backend using XMPP file copy
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
95 # Here we cheat because we know we are on the same host, and we don't
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
96 # check data. Referee will have to parse the song himself to check it
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
97 client = self.host.getClient(profile)
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
98 if not client:
765
787ee59dba9c plugins radiocol, xep-0054: better handling of upload errors:
souliane <souliane@mailoo.org>
parents: 764
diff changeset
99 raise exceptions.NotConnectedProfileError(_("Can't access profile's data"))
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
100 try:
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
101 song = OggVorbis(song_path)
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
102 except OggVorbisHeaderError:
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
103 #this file is not ogg vorbis, we reject it
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
104 self.deleteFile(song_path) # FIXME: same host trick (see note above)
765
787ee59dba9c plugins radiocol, xep-0054: better handling of upload errors:
souliane <souliane@mailoo.org>
parents: 764
diff changeset
105 return defer.fail(exceptions.DataError("Uploaded file is not Ogg Vorbis song, only Ogg Vorbis songs are acceptable"))
714
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
106 attrs = {'filename': os.path.basename(song_path),
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
107 'title': song.get("title", ["Unknown"])[0],
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
108 'artist': song.get("artist", ["Unknown"])[0],
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
109 'album': song.get("album", ["Unknown"])[0],
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
110 'length': str(song.info.length)
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
111 }
683
75e4f5e2cc65 plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents: 609
diff changeset
112 radio_data = self.games[jid.JID(referee).userhost()] # FIXME: referee comes from Libervia's client side, it's unsecure
714
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
113 radio_data['to_delete'][attrs['filename']] = song_path # FIXME: works only because of the same host trick, see the note under the docstring
826
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
114
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
115 # XXX: avoid deferToThread which is causing testing troubles. When using deferToThread,
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
116 # the callbacks that are added (by the test) to the Deferred instance returned by this
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
117 # method are not run. And if you run d.callback again, you get a AlreadyCalledError.
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
118 d = defer.Deferred()
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
119 d.addCallback(self.send, ('', 'song_added'), attrs, profile=profile)
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
120 d.callback(jid.JID(referee))
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
121 return d
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
122
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
123 def playNext(self, room_jid, profile):
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
124 """"Play next song in queue if exists, and put a timer
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
125 which trigger after the song has been played to play next one"""
464
794f60e2da27 plugin radiocol: fixed missing import
Goffi <goffi@goffi.org>
parents: 459
diff changeset
126 #TODO: songs need to be erased once played or found invalids
577
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
127 # ==> unlink done the Q&D way with the same host trick (see above)
683
75e4f5e2cc65 plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents: 609
diff changeset
128 radio_data = self.games[room_jid.userhost()]
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
129 if len(radio_data['players']) == 0:
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
130 debug(_('No more participants in the radiocol: cleaning data'))
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
131 radio_data['queue'] = []
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
132 for filename in radio_data['to_delete']:
764
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
133 self.deleteFile(filename, radio_data)
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
134 radio_data['to_delete'] = {}
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
135 queue = radio_data['queue']
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
136 if not queue:
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
137 #nothing left to play, we need to wait for uploads
827
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
138 radio_data['playing'] = None
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
139 return
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
140 song = queue.pop(0)
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
141 filename, length = song['filename'], float(song['length'])
714
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
142 self.send(room_jid, ('', 'play'), {'filename': filename}, profile=profile)
827
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
143 radio_data['playing'] = song
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
144 radio_data['playing_time'] = time.time()
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
145
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
146 if not radio_data['upload'] and len(queue) < QUEUE_LIMIT:
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
147 #upload is blocked and we now have resources to get more, we reactivate it
714
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
148 self.send(room_jid, ('', 'upload_ok'), profile=profile)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
149 radio_data['upload'] = True
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
150
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
151 reactor.callLater(length, self.playNext, room_jid, profile)
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
152 #we wait more than the song length to delete the file, to manage poorly reactive networks/clients
764
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
153 reactor.callLater(length + 90, self.deleteFile, filename, radio_data) # FIXME: same host trick (see above)
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
154
764
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
155 def deleteFile(self, filename, radio_data=None):
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
156 """
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
157 Delete a previously uploaded file.
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
158 @param filename: filename to delete, or full filepath if radio_data is None
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
159 @param radio_data: current game data
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
160 @return: True if the file has been deleted
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
161 """
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
162 if radio_data:
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
163 try:
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
164 file_to_delete = radio_data['to_delete'][filename]
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
165 except KeyError:
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
166 error(_("INTERNAL ERROR: can't find full path of the song to delete"))
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
167 return False
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
168 else:
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
169 file_to_delete = filename
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
170 try:
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
171 unlink(file_to_delete)
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
172 except OSError:
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
173 error(_("INTERNAL ERROR: can't find %s on the file system" % file_to_delete))
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
174 return False
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
175 return True
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
176
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
177 def room_game_cmd(self, mess_elt, profile):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
178 from_jid = jid.JID(mess_elt['from'])
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 room_jid = jid.JID(from_jid.userhost())
826
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
180 nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid.userhost(), profile)
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
181
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 radio_elt = mess_elt.firstChildElement()
683
75e4f5e2cc65 plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents: 609
diff changeset
183 radio_data = self.games[room_jid.userhost()]
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
184 if 'queue' in radio_data:
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
185 queue = radio_data['queue']
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
186
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
187 from_referee = self.isReferee(room_jid.userhost(), from_jid.resource)
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
188 to_referee = self.isReferee(room_jid.userhost(), jid.JID(mess_elt['to']).user)
826
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
189 is_player = self.isPlayer(room_jid.userhost(), nick)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 for elt in radio_elt.elements():
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
191 if not from_referee and not (to_referee and elt.name == 'song_added'):
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
192 continue # sender must be referee, expect when a song is submitted
826
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
193 if not is_player and (elt.name not in ('started', 'players')):
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
194 continue # user is in the room but not playing
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
195
826
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
196 if elt.name in ('started', 'players'): # new game created and/or players list updated
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
197 players = []
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
198 for player in elt.elements():
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
199 players.append(unicode(player))
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
200 signal = self.host.bridge.radiocolStarted if elt.name == 'started' else self.host.bridge.radiocolPlayers
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
201 signal(room_jid.userhost(), from_jid.full(), players, [QUEUE_TO_START, QUEUE_LIMIT], profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
202 elif elt.name == 'preload': # a song is in queue and must be preloaded
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
203 self.host.bridge.radiocolPreload(room_jid.userhost(), elt['timestamp'], elt['filename'], elt['title'], elt['artist'], elt['album'], profile)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
204 elif elt.name == 'play':
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
205 self.host.bridge.radiocolPlay(room_jid.userhost(), elt['filename'], profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
206 elif elt.name == 'song_rejected': # a song has been refused
577
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
207 self.host.bridge.radiocolSongRejected(room_jid.userhost(), elt['reason'], profile)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
208 elif elt.name == 'no_upload':
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
209 self.host.bridge.radiocolNoUpload(room_jid.userhost(), profile)
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
210 elif elt.name == 'upload_ok':
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
211 self.host.bridge.radiocolUploadOk(room_jid.userhost(), profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
212 elif elt.name == 'song_added': # a song has been added
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
213 #FIXME: we are KISS for the proof of concept: every song is added, to a limit of 3 in queue.
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
214 # Need to manage some sort of rules to allow peoples to send songs
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
215 if len(queue) >= QUEUE_LIMIT:
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
216 #there are already too many songs in queue, we reject this one
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
217 #FIXME: add an error code
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
218 self.send(from_jid, ('', 'song_rejected'), {'reason': "Too many songs in queue"}, profile=profile)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
219 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
220
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
221 #The song is accepted and added in queue
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
222 preload_elt = self.__create_preload_elt(from_jid.resource, elt)
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
223 queue.append(preload_elt)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
224
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
225 if len(queue) >= QUEUE_LIMIT:
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
226 #We are at the limit, we refuse new upload until next play
714
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
227 self.send(room_jid, ('', 'no_upload'), profile=profile)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
228 radio_data['upload'] = False
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
229
714
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
230 self.send(room_jid, preload_elt, profile=profile)
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
231 if not radio_data['playing'] and len(queue) == QUEUE_TO_START:
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
232 # We have not started playing yet, and we have QUEUE_TO_START
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
233 # songs in queue. We can now start the party :)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
234 self.playNext(room_jid, profile)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
235 else:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
236 error(_('Unmanaged game element: %s') % elt.name)
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
237
825
e3f4d80f987d plugins room_games, radiocol: better synchronization after a user joins a running game
souliane <souliane@mailoo.org>
parents: 811
diff changeset
238 def getSyncData(self, room_jid_s, force_nicks=[]):
e3f4d80f987d plugins room_games, radiocol: better synchronization after a user joins a running game
souliane <souliane@mailoo.org>
parents: 811
diff changeset
239 data = {}
827
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
240 game_data = self.games[room_jid_s]
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
241 status = game_data['status']
825
e3f4d80f987d plugins room_games, radiocol: better synchronization after a user joins a running game
souliane <souliane@mailoo.org>
parents: 811
diff changeset
242 nicks = [nick for nick in status if status[nick] == 'desync']
e3f4d80f987d plugins room_games, radiocol: better synchronization after a user joins a running game
souliane <souliane@mailoo.org>
parents: 811
diff changeset
243 for nick in force_nicks:
e3f4d80f987d plugins room_games, radiocol: better synchronization after a user joins a running game
souliane <souliane@mailoo.org>
parents: 811
diff changeset
244 if nick not in nicks:
e3f4d80f987d plugins room_games, radiocol: better synchronization after a user joins a running game
souliane <souliane@mailoo.org>
parents: 811
diff changeset
245 nicks.append(nick)
e3f4d80f987d plugins room_games, radiocol: better synchronization after a user joins a running game
souliane <souliane@mailoo.org>
parents: 811
diff changeset
246 for nick in nicks:
827
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
247 elements = []
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
248 if game_data['playing']:
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
249 preload = copy.deepcopy(game_data['playing'])
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
250 preload['filename'] += '#t=%.2f' % (time.time() - game_data['playing_time'])
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
251 elements.append(preload)
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
252 play = domish.Element(('', 'play'))
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
253 play['filename'] = preload['filename']
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
254 elements.append(play)
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
255 if len(game_data['queue']) > 0:
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
256 elements.extend(copy.deepcopy(game_data['queue']))
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
257 if len(game_data['queue']) == QUEUE_LIMIT:
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
258 elements.append(domish.Element(('', 'no_upload')))
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
259 if data:
215a2cb15e2d plugin radiocol: sync data includes a "jump to time" info
souliane <souliane@mailoo.org>
parents: 826
diff changeset
260 data[nick] = elements
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
261 return data