Mercurial > libervia-backend
annotate src/plugins/plugin_misc_radiocol.py @ 717:358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
- "MUC user joined", "MUC user left" and class XMPPHandler are managed directly in RoomGame
- renamed __init__ parameters 'player_init_data' to 'player_init' and 'options' to 'game_init'
- pass the players list in radiocol method 'createGame' and signal 'radiocolStarted' (needed for invitation system and for UI players identification)
- added some parameters to manage who can invite, who can join, who to wait for... managed with check***Auth methods
- joining a game that is already launched may be possible, regarding these parameters and the invitation list
- leave and join a game again is partly managed: new tarot round is launched, we should keep playing the same round instead
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 21 Nov 2013 15:49:53 +0100 |
parents | ecc5a5b34ee1 |
children | 074970227bc0 |
rev | line source |
---|---|
450 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
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 |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
450 | 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 | 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 | 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 | 19 |
20 from logging import debug, info, warning, error | |
21 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
|
22 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
|
23 from twisted.words.protocols.jabber import jid |
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 |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
25 import os.path |
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
|
26 from os import unlink |
464
794f60e2da27
plugin radiocol: fixed missing import
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
27 from mutagen.oggvorbis import OggVorbis, OggVorbisHeaderError |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
28 from sat.tools.plugins.games import RoomGame |
450 | 29 |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
30 |
450 | 31 NC_RADIOCOL = 'http://www.goffi.org/protocol/radiocol' |
32 RADIOC_TAG = 'radiocol' | |
33 | |
34 PLUGIN_INFO = { | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
35 "name": "Radio collective plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
36 "import_name": "Radiocol", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
37 "type": "Exp", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
38 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
39 "dependencies": ["XEP-0045", "XEP-0249"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
40 "main": "Radiocol", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
41 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
42 "description": _("""Implementation of radio collective""") |
450 | 43 } |
44 | |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
45 QUEUE_LIMIT = 2 |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
46 |
450 | 47 |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
48 class Radiocol(RoomGame): |
450 | 49 |
50 def __init__(self, host): | |
51 info(_("Radio collective initialization")) | |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
52 RoomGame.__init__(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG), |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
53 game_init={'queue': [], 'upload': True, 'playing': False, 'to_delete': {}}) |
450 | 54 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
|
55 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
|
56 host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame) |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
57 host.bridge.addMethod("radiocolSongAdded", ".plugin", in_sign='sss', out_sign='', method=self.radiocolSongAdded) |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
58 host.bridge.addSignal("radiocolPlayers", ".plugin", signature='ssass') # room_jid, referee, players, profile |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
59 host.bridge.addSignal("radiocolStarted", ".plugin", signature='ssass') # room_jid, referee, players, profile |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
60 host.bridge.addSignal("radiocolSongRejected", ".plugin", signature='sss') # room_jid, reason, profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
61 host.bridge.addSignal("radiocolPreload", ".plugin", signature='ssssss') # room_jid, filename, title, artist, album, profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
62 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
|
63 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
|
64 host.bridge.addSignal("radiocolUploadOk", ".plugin", signature='ss') # room_jid, profile |
450 | 65 |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
66 def __create_preload_elt(self, sender, filename, title, artist, album): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
67 preload_elt = domish.Element((None, 'preload')) |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
68 preload_elt['sender'] = sender |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
69 preload_elt['filename'] = filename # 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
|
70 preload_elt['title'] = title |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
71 preload_elt['artist'] = artist |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
72 preload_elt['album'] = album |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
73 return preload_elt |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
74 |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
75 def radiocolSongAdded(self, referee, song_path, profile): |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
76 """This method is called by libervia when a song has been uploaded |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
77 @param room_jid_param: jid of the room |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
78 @song_path: absolute path of the song added |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
79 @param profile_key: %(doc_profile_key)s""" |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
80 #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
|
81 # be streamed to the backend using XMPP file copy |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
82 # 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
|
83 # 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
|
84 client = self.host.getClient(profile) |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
85 if not client: |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
86 error(_("Can't access profile's data")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
577
diff
changeset
|
87 return |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
88 try: |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
89 song = OggVorbis(song_path) |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
90 except OggVorbisHeaderError: |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
91 #this file is not ogg vorbis, we reject it |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
92 unlink(song_path) # FIXME: same host trick (see note above) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
93 self.host.bridge.radiocolSongRejected(jid.JID(referee).userhost(), |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
94 "Uploaded file is not Ogg Vorbis song, only Ogg Vorbis songs are acceptable", profile) |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
95 """mess = self.createGameElt(jid.JID(referee)) |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
96 reject_elt = mess.firstChildElement().addElement(('','song_rejected')) |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
97 reject_elt['sender'] = client.jid |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
98 reject_elt['reason'] = "Uploaded file is not Ogg Vorbis song, only Ogg Vorbis songs are acceptable" |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
99 #FIXME: add an error code |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
100 self.host.profiles[profile].xmlstream.send(mess)""" |
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
101 return |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
102 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
|
103 '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
|
104 '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
|
105 '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
|
106 'length': str(song.info.length) |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
107 } |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
108 self.send(jid.JID(referee), ('', 'song_added'), attrs, profile=profile) |
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
|
109 |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
110 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
|
111 radio_data['to_delete'][attrs['filename']] = song_path # FIXME: works only because of the same host trick, see the note under the docstring |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
112 |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
113 def playNext(self, room_jid, profile): |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
114 """"Play next sont in queue if exists, and put a timer |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
115 which trigger after the song has been played to play next one""" |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
116 #TODO: need to check that there are still peoples in the room |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
117 # and clean the datas/stop the playlist if it's not the case |
464
794f60e2da27
plugin radiocol: fixed missing import
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
118 #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
|
119 # ==> 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
|
120 radio_data = self.games[room_jid.userhost()] |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
121 queue = radio_data['queue'] |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
122 if not queue: |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
123 #nothing left to play, we need to wait for uploads |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
124 radio_data['playing'] = False |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
125 return |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
126 |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
127 filename, length = queue.pop(0) |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
128 self.send(room_jid, ('', 'play'), {'filename': filename}, profile=profile) |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
129 |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
130 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
|
131 #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
|
132 self.send(room_jid, ('', 'upload_ok'), profile=profile) |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
133 radio_data['upload'] = True |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
134 |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
135 reactor.callLater(length, self.playNext, room_jid, profile) |
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
|
136 try: |
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
|
137 file_to_delete = radio_data['to_delete'][filename] |
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
|
138 except KeyError: |
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
|
139 error(_("INTERNAL ERROR: can't find full path of the song to delete")) |
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
|
140 return |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
577
diff
changeset
|
141 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
577
diff
changeset
|
142 #we wait more than the song length to delete the file, to manage poorly reactive networks/clients |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
143 reactor.callLater(length + 90, unlink, file_to_delete) # FIXME: same host trick (see above) |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
144 |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
145 def room_game_cmd(self, mess_elt, profile): |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
146 #FIXME: we should check sender (is it referee ?) here before accepting commands |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
577
diff
changeset
|
147 from_jid = jid.JID(mess_elt['from']) |
450 | 148 room_jid = jid.JID(from_jid.userhost()) |
149 radio_elt = mess_elt.firstChildElement() | |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
150 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
|
151 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
|
152 queue = radio_data['queue'] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
577
diff
changeset
|
153 |
450 | 154 for elt in radio_elt.elements(): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
577
diff
changeset
|
155 |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
156 if elt.name == 'started' or elt.name == 'players': # new game created |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
157 players = [] |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
158 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
|
159 players.append(unicode(player)) |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
160 signal = self.host.bridge.radiocolStarted if elt.name == 'started' else self.host.bridge.radiocolPlayers |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
161 signal(room_jid.userhost(), from_jid.full(), players, profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
162 elif elt.name == 'preload': # a song is in queue and must be preloaded |
455
72522263cbc9
plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents:
453
diff
changeset
|
163 self.host.bridge.radiocolPreload(room_jid.userhost(), 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
|
164 elif elt.name == 'play': |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 elif elt.name == 'no_upload': |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
169 self.host.bridge.radiocolNoUpload(room_jid.userhost(), profile) |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
170 elif elt.name == 'upload_ok': |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
171 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
|
172 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
|
173 #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
|
174 # Need to manage some sort of rules to allow peoples to send songs |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
577
diff
changeset
|
175 |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
176 if len(queue) >= QUEUE_LIMIT: |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
177 #there are already too many songs in queue, we reject this one |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
178 attrs = {'sender': from_jid.resource, |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
179 'reason': "Too many songs in queue" |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
180 } |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
181 #FIXME: add an error code |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
182 self.send(room_jid, ('', 'song_rejected'), attrs, profile=profile) |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
183 return |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
577
diff
changeset
|
184 |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
185 #The song is accepted and added in queue |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
186 queue.append((elt['filename'], float(elt['length']))) |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
187 |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
188 if len(queue) >= QUEUE_LIMIT: |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
189 #We are at the limit, we refuse new upload until next play |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
190 #FIXME: add an error code |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
191 self.send(room_jid, ('', 'no_upload'), profile=profile) |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
192 radio_data['upload'] = False |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
193 |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
194 preload_elt = self.__create_preload_elt(from_jid.resource, |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
195 elt['filename'], |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
196 elt['title'], |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
197 elt['artist'], |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
198 elt['album']) |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
199 self.send(room_jid, preload_elt, profile=profile) |
457
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
200 if not radio_data['playing'] and len(queue) == 2: |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
201 #we have not started playing yet, and we have 2 songs in queue |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
202 #we can now start the party :) |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
203 radio_data['playing'] = True |
fbe7c9118ce4
plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents:
456
diff
changeset
|
204 self.playNext(room_jid, profile) |
450 | 205 else: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
206 error(_('Unmanaged game element: %s') % elt.name) |