annotate src/plugins/plugin_misc_radiocol.py @ 609:84a6e83157c2

fixed licences in docstrings (they are now in comments)
author Goffi <goffi@goffi.org>
date Fri, 08 Mar 2013 00:36:22 +0100
parents e629371a28d3
children 75e4f5e2cc65
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
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
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
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from logging import debug, info, warning, error
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
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
25 from wokkel import disco, iwokkel
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from zope.interface import implements
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
29 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
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
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 try:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from twisted.words.protocols.xmlstream import XMPPHandler
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 except ImportError:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from wokkel.subprotocols import XMPPHandler
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 MESSAGE = '/message'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 NC_RADIOCOL = 'http://www.goffi.org/protocol/radiocol'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 RADIOC_TAG = 'radiocol'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 RADIOC_REQUEST = MESSAGE + '/' + RADIOC_TAG + '[@xmlns="' + NC_RADIOCOL + '"]'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
44 "name": "Radio collective plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
45 "import_name": "Radiocol",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
46 "type": "Exp",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
47 "protocols": [],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
48 "dependencies": ["XEP-0045", "XEP-0249"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
49 "main": "Radiocol",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
50 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
51 "description": _("""Implementation of radio collective""")
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 }
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
54 QUEUE_LIMIT = 2
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
55
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
57 class Radiocol(object):
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def __init__(self, host):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 info(_("Radio collective initialization"))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.host = host
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
62 self.radios = {}
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
63 host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='ass', out_sign='', method=self.radiocolLaunch)
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
64 host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='ss', out_sign='', method=self.radiocolCreate)
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
65 host.bridge.addMethod("radiocolSongAdded", ".plugin", in_sign='sss', out_sign='', method=self.radiocolSongAdded)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
66 host.bridge.addSignal("radiocolStarted", ".plugin", signature='sss') # room_jid, referee, profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
67 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
68 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
69 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
70 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
71 host.bridge.addSignal("radiocolUploadOk", ".plugin", signature='ss') # room_jid, profile
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 host.trigger.add("MUC user joined", self.userJoinedTrigger)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 def createRadiocolElt(self, to_jid, type="normal"):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 type = "normal" if to_jid.resource else "groupchat"
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
76 elt = domish.Element((None, 'message'))
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 elt["to"] = to_jid.full()
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 elt["type"] = type
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 elt.addElement((NC_RADIOCOL, RADIOC_TAG))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 return elt
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
81
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def __create_started_elt(self):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 """Create a game_started domish element"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
84 started_elt = domish.Element((None, 'started'))
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 return started_elt
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
87 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
88 preload_elt = domish.Element((None, 'preload'))
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
89 preload_elt['sender'] = sender
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
90 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
91 preload_elt['title'] = title
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
92 preload_elt['artist'] = artist
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
93 preload_elt['album'] = album
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
94 return preload_elt
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
95
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 def userJoinedTrigger(self, room, user, profile):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 """This trigger is used to check if we are waiting people in this room,
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 and to create a game if everybody is here"""
456
ba6e1feda03e plugin radiocol: fixed autocreation of radiocol for new comers
Goffi <goffi@goffi.org>
parents: 455
diff changeset
99 room_jid = room.occupantJID.userhost()
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
100 if room_jid in self.radios and self.radios[room_jid]["referee"] == room.occupantJID.full():
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 #we are in a radiocol room, let's start the party !
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
102 mess = self.createRadiocolElt(jid.JID(room_jid + '/' + user.nick))
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 mess.firstChildElement().addChild(self.__create_started_elt())
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.host.profiles[profile].xmlstream.send(mess)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 return True
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 def radiocolLaunch(self, occupants, profile_key='@DEFAULT@'):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 """Launch a game: helper method to create a room, invite occupants, and create the radiocol
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 @param occupants: list for occupants jid"""
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 debug(_('Launching radiocol'))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 profile = self.host.memory.getProfileName(profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if not profile:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 error(_("Unknown profile"))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 return
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 def radiocolRoomJoined(room):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 print "radiocolRoomJoined"
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 _room_jid = room.occupantJID.userhostJID()
456
ba6e1feda03e plugin radiocol: fixed autocreation of radiocol for new comers
Goffi <goffi@goffi.org>
parents: 455
diff changeset
119 self.radiocolCreate(_room_jid.userhost(), profile_key=profile)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 for occupant in occupants:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
121 self.host.plugins["XEP-0249"].invite(jid.JID(occupant), room.occupantJID.userhostJID(), {"game": "Radiocol"}, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
122
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 def after_init(ignore):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 room_name = "sat_radiocol_%s" % self.host.plugins["XEP-0045"].getUniqueName(profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 print "\n\n===> room_name:", room_name
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 muc_service = None
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 for service in self.host.memory.getServerServiceEntities("conference", "text", profile):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 if not ".irc." in service.userhost():
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
129 #FIXME:
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 #This awfull ugly hack is here to avoid an issue with openfire: the irc gateway
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 #use "conference/text" identity (instead of "conference/irc"), there is certainly a better way
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 #to manage this, but this hack fill do it for test purpose
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 muc_service = service
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 break
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 if not muc_service:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 error(_("Can't find a MUC service"))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
138
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 _jid, xmlstream = self.host.getJidNStream(profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 d = self.host.plugins["XEP-0045"].join(jid.JID("%s@%s" % (room_name, muc_service.userhost())), _jid.user, {}, profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 d.addCallback(radiocolRoomJoined)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 client = self.host.getClient(profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 if not client:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 error(_('No client for this profile key: %s') % profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 return
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 client.client_initialized.addCallback(after_init)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 def radiocolCreate(self, room_jid_param, profile_key='@DEFAULT@'):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 """Create a new game
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 @param room_jid_param: jid of the room
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 @param profile_key: %(doc_profile_key)s"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
153 debug(_("Creating Radiocol"))
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 room_jid = jid.JID(room_jid_param)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155 profile = self.host.memory.getProfileName(profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 if not profile:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
157 error(_("profile %s is unknown") % profile_key)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 return
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
159 if room_jid in self.radios:
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
160 warning(_("Radiocol already started in room %s") % room_jid.userhost())
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161 else:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162 room_nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid.userhost(), profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 if not room_nick:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
164 error('Internal error')
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 return
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166 referee = room_jid.userhost() + '/' + room_nick
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
167 self.radios[room_jid.userhost()] = {'referee': referee, 'queue': [], 'upload': True, 'playing': False, 'occupants_data': {}, 'to_delete': {}}
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 mess = self.createRadiocolElt(jid.JID(room_jid.userhost()))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 mess.firstChildElement().addChild(self.__create_started_elt())
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170 self.host.profiles[profile].xmlstream.send(mess)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
172 def radiocolSongAdded(self, referee, song_path, profile):
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
173 """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
174 @param room_jid_param: jid of the room
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
175 @song_path: absolute path of the song added
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
176 @param profile_key: %(doc_profile_key)s"""
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
177 #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
178 # be streamed to the backend using XMPP file copy
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
179 # 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
180 # 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
181 client = self.host.getClient(profile)
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
182 if not client:
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
183 error(_("Can't access profile's data"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
184 return
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
185 try:
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
186 song = OggVorbis(song_path)
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
187 except OggVorbisHeaderError:
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
188 #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
189 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
190 self.host.bridge.radiocolSongRejected(jid.JID(referee).userhost(),
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
191 "Uploaded file is not Ogg Vorbis song, only Ogg Vorbis songs are acceptable", profile)
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
192 """mess = self.createRadiocolElt(jid.JID(referee))
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
193 reject_elt = mess.firstChildElement().addElement(('','song_rejected'))
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
194 reject_elt['sender'] = client.jid
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
195 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
196 #FIXME: add an error code
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
197 self.host.profiles[profile].xmlstream.send(mess)"""
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
198 return
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
199 title = song.get("title", ["Unknown"])[0]
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
200 artist = song.get("artist", ["Unknown"])[0]
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
201 album = song.get("album", ["Unknown"])[0]
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
202 length = song.info.length
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
203 mess = self.createRadiocolElt(jid.JID(referee))
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
204 added_elt = mess.firstChildElement().addElement(('', 'song_added'))
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
205 added_elt['filename'] = filename = os.path.basename(song_path)
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
206 added_elt['title'] = title
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
207 added_elt['artist'] = artist
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
208 added_elt['album'] = album
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
209 added_elt['length'] = str(length)
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
210 self.host.profiles[profile].xmlstream.send(mess)
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
211
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
212 radio_data = self.radios[jid.JID(referee).userhost()] # FIXME: referee comes from Libervia's client side, it's unsecure
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
213 radio_data['to_delete'][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
214
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
215 def playNext(self, room_jid, profile):
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
216 """"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
217 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
218 #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
219 # 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
220 #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
221 # ==> unlink done the Q&D way with the same host trick (see above)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
222 radio_data = self.radios[room_jid.userhost()]
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
223 queue = radio_data['queue']
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
224 if not queue:
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
225 #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
226 radio_data['playing'] = False
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
227 return
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
228
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
229 filename, length = queue.pop(0)
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
230 mess = self.createRadiocolElt(room_jid)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
231 play_elt = mess.firstChildElement().addElement(('', 'play'))
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
232 play_elt['filename'] = filename
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
233 self.host.profiles[profile].xmlstream.send(mess)
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
234
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
235 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
236 #upload is blocked and we now have resources to get more, we reactivate it
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
237 mess = self.createRadiocolElt(room_jid)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
238 no_upload_elt = mess.firstChildElement().addElement(('', 'upload_ok'))
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
239 self.host.profiles[profile].xmlstream.send(mess)
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
240 radio_data['upload'] = True
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
241
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
242 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
243 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
244 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
245 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
246 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
247 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
248
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
249 #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
250 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
251
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
252 def radiocol_game_cmd(self, mess_elt, profile):
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
253 #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
254 from_jid = jid.JID(mess_elt['from'])
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
255 room_jid = jid.JID(from_jid.userhost())
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
256 radio_elt = mess_elt.firstChildElement()
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
257 radio_data = self.radios[room_jid.userhost()]
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
258 occupants_data = radio_data['occupants_data']
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
259 queue = radio_data['queue']
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
260
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
261 for elt in radio_elt.elements():
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
262
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
263 if elt.name == 'started': # new game created
453
5731b038fc7f plugin radiocol: removed occupants list in radiocolStarted signal
Goffi <goffi@goffi.org>
parents: 450
diff changeset
264 self.host.bridge.radiocolStarted(room_jid.userhost(), from_jid.full(), profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
265 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
266 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
267 elif elt.name == 'play':
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
268 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
269 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
270 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
271 elif elt.name == 'no_upload':
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
272 self.host.bridge.radiocolNoUpload(room_jid.userhost(), profile)
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
273 elif elt.name == 'upload_ok':
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
274 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
275 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
276 #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
277 # 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
278
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
279 if len(queue) >= QUEUE_LIMIT:
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
280 #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
281 mess = self.createRadiocolElt(room_jid)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
282 reject_elt = mess.firstChildElement().addElement(('', 'song_rejected'))
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
283 reject_elt['sender'] = from_jid.resource
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
284 reject_elt['reason'] = "Too many songs in queue"
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
285 #FIXME: add an error code
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
286 self.host.profiles[profile].xmlstream.send(mess)
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
287 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
288
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
289 #The song is accepted and added in queue
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
290 queue.append((elt['filename'], float(elt['length'])))
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
291
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
292 if len(queue) >= QUEUE_LIMIT:
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
293 #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
294 mess = self.createRadiocolElt(room_jid)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
295 no_upload_elt = mess.firstChildElement().addElement(('', 'no_upload'))
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
296 #FIXME: add an error code
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
297 self.host.profiles[profile].xmlstream.send(mess)
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
298 radio_data['upload'] = False
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
299
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
300 mess = self.createRadiocolElt(room_jid)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
301 preload_elt = self.__create_preload_elt(from_jid.resource,
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
302 elt['filename'],
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
303 elt['title'],
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
304 elt['artist'],
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
305 elt['album'])
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
306 mess.firstChildElement().addChild(preload_elt)
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
307 self.host.profiles[profile].xmlstream.send(mess)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
308 if not radio_data['playing'] and len(queue) == 2:
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
309 #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
310 #we can now start the party :)
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
311 radio_data['playing'] = True
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
312 self.playNext(room_jid, profile)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
313 else:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
314 error(_('Unmanaged game element: %s') % elt.name)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
315
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
316 def getHandler(self, profile):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
317 return RadiocolHandler(self)
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
318
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
319
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
320 class RadiocolHandler (XMPPHandler):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
321 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
322
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
323 def __init__(self, plugin_parent):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
324 self.plugin_parent = plugin_parent
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
325 self.host = plugin_parent.host
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
326
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
327 def connectionInitialized(self):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
328 self.xmlstream.addObserver(RADIOC_REQUEST, self.plugin_parent.radiocol_game_cmd, profile=self.parent.profile)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
329
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
330 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
331 return [disco.DiscoFeature(NC_RADIOCOL)]
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
332
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
333 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
334 return []