annotate browser_side/radiocol.py @ 285:4f0c2fea358a

browser_side (plugin radiocol): use the status label to give more information
author souliane <souliane@mailoo.org>
date Tue, 26 Nov 2013 19:51:02 +0100
parents bee4719af9b9
children e76ec07be8e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
165
9763dec220ed dates update
Goffi <goffi@goffi.org>
parents: 151
diff changeset
6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org>
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
22 import pyjd # this is dummy in pyjs
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.VerticalPanel import VerticalPanel
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from pyjamas.ui.HorizontalPanel import HorizontalPanel
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
25 from pyjamas.ui.FlexTable import FlexTable
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.FormPanel import FormPanel
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.Label import Label
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.Button import Button
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.ClickListener import ClickHandler
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
30 from pyjamas.ui.Hidden import Hidden
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
31 from pyjamas.ui.HTML import HTML
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from pyjamas import Window
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
33 from pyjamas.Timer import Timer
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
34 from __pyjamas__ import JS
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from tools import html_sanitize
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
37 from tools import FilterFileUpload
284
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
38 from sat_frontends.tools.misc import DEFAULT_MUC
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
41 class MetadataPanel(FlexTable):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def __init__(self):
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
44 FlexTable.__init__(self)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
45 title_lbl = Label("title:")
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
46 title_lbl.setStyleName('radiocol_metadata_lbl')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
47 artist_lbl = Label("artist:")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
48 artist_lbl.setStyleName('radiocol_metadata_lbl')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
49 album_lbl = Label("album:")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
50 album_lbl.setStyleName('radiocol_metadata_lbl')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
51 self.title = Label("")
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
52 self.title.setStyleName('radiocol_metadata')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
53 self.artist = Label("")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
54 self.artist.setStyleName('radiocol_metadata')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
55 self.album = Label("")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
56 self.album.setStyleName('radiocol_metadata')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
57 self.setWidget(0, 0, title_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
58 self.setWidget(1, 0, artist_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
59 self.setWidget(2, 0, album_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
60 self.setWidget(0, 1, self.title)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
61 self.setWidget(1, 1, self.artist)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
62 self.setWidget(2, 1, self.album)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
63 self.setStyleName("radiocol_metadata_pnl")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
64
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
65 def setTitle(self, title):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
66 self.title.setText(title)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
67
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
68 def setArtist(self, artist):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
69 self.artist.setText(artist)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
70
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
71 def setAlbum(self, album):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
72 self.album.setText(album)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
74
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 class ControlPanel(FormPanel):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 """Panel used to show controls to add a song, or vote for the current one"""
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
78 def __init__(self, parent):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 FormPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.setEncoding(FormPanel.ENCODING_MULTIPART)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 self.setMethod(FormPanel.METHOD_POST)
151
a159cc29b556 server side: file upload is now more generic:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
82 self.setAction("upload_radiocol")
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
83 self._parent = parent
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 hPanel = HorizontalPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 hPanel.setSpacing(5)
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
87 types = [('audio/ogg', '*.ogg', 'Ogg Vorbis Audio'),
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
88 ('video/ogg', '*.ogv', 'Ogg Vorbis Video'),
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
89 ('application/ogg', '*.ogx', 'Ogg Vorbis Multiplex')]
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
90 self.file_upload = FilterFileUpload("song", 5, types)
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
91 hPanel.add(self.file_upload)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
93 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick"))
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
94 hPanel.add(self.upload_btn)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
96 self.status = Label()
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
97 self.updateStatus()
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
98 hPanel.add(self.status)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
99
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
100
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
101 #We need to know the referee
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
102 referee_field = Hidden('referee', self._parent.referee)
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
103 hPanel.add(referee_field)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
105 self.add(hPanel)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.addFormHandler(self)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
107
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
108 def updateStatus(self):
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
109 # TODO: the status should be different if a song is being played or not
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
110 queue = self._parent.getQueueSize()
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
111 queue_data = self._parent.queue_data
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
112 if queue < queue_data[0]:
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
113 left = queue_data[0] - queue
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
114 self.status.setText("[we need %d more song%s]" % (left, "s" if left > 1 else ""))
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
115 elif queue < queue_data[1]:
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
116 left = queue_data[1] - queue
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
117 self.status.setText("[%d available spot%s]" % (left, "s" if left > 1 else ""))
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
118 elif queue >= queue_data[1]:
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
119 self.status.setText("[The queue is currently full]")
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
120 self.status.setStyleName('radiocol_status')
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 def onBtnClick(self):
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
123 if self.file_upload.check():
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
124 self.submit()
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
125 self.file_upload.setFilename("")
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
126 self.status.setText('[Submitting, please wait...]')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
127
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def onSubmit(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 pass
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
131 def blockUpload(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
132 self.file_upload.setVisible(False)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
133 self.upload_btn.setEnabled(False)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
134
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
135 def unblockUpload(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
136 self.file_upload.setVisible(True)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
137 self.upload_btn.setEnabled(True)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
138
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
139 def setTemporaryStatus(self, text, style):
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
140 self.status.setText(text)
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
141 self.status.setStyleName('radiocol_upload_status_%s' % style)
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
142 Timer(5000, self.updateStatus)
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
143
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def onSubmitComplete(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 result = event.getResults()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 if result == "OK":
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
147 self.setTemporaryStatus('[Your song has been added to queue]', "ok")
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 elif result == "KO":
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
149 self.setTemporaryStatus('[Something went wrong during your song upload]', "ko")
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 else:
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 Window.alert('Submit error: %s' % result)
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
152 self.status.setText('')
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
154
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
155 class Player(HTML):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
156
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
157 def __init__(self, player_id, metadata_panel):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
158 HTML.__init__(self)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
159 self._id = player_id
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
160 self.metadata = metadata_panel
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
161 self.title = ""
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
162 self.artist = ""
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
163 self.album = ""
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
164 self.filename = None
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
165 self.played = False # True when song is playing/played, become False on preload
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
166
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
167 def preload(self, filename, title, artist, album):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
168 """preload the song but doesn't play it"""
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
169 self.filename = filename
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
170 self.title = title
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
171 self.artist = artist
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
172 self.album = album
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
173 self.played = False
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
174 self.setHTML('<audio id="%s" style="display: none" preload="auto" src="radiocol/%s" />' % (self._id, html_sanitize(filename)))
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
175 print "preloading %s in %s" % (title, self._id)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
176
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
177 def play(self):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
178 """actually play the song"""
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
179 self.played = True
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
180 self.metadata.setTitle(self.title)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
181 self.metadata.setArtist(self.artist)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
182 self.metadata.setAlbum(self.album)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
183
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
184 JS("""
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
185 var player = top.document.getElementById(this._id);
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
186 player.play();
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
187 """)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
188
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
189
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 class RadioColPanel(HorizontalPanel, ClickHandler):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
192 def __init__(self, parent, referee, player_nick, players, queue_data):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
193 HorizontalPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194 ClickHandler.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
195 self._parent = parent
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
196 self.referee = referee
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
197 self.queue_data = queue_data
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
198 self.setStyleName("radiocolPanel")
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
199 self.setHeight('30%')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
200
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
201 # Now we set up the layout
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
202 self.left_panel = VerticalPanel()
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
203 self.left_panel.setStyleName("radiocol_left_panel")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
204 self.left_panel.setHeight('100%')
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
205 self.add(self.left_panel)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
206 self.right_panel = VerticalPanel()
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
207 self.metadata_panel = MetadataPanel()
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
208 self.right_panel.add(self.metadata_panel)
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
209 self.control_panel = ControlPanel(self)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
210 self.right_panel.add(self.control_panel)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
211 self.add(self.right_panel)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
212 #self.right_panel.setBorderWidth(1)
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
213 self.next_songs = []
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
214 self.players = [Player("player_%d" % i, self.metadata_panel) for i in range(4)]
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
215 self.current_player = None
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
216 for player in self.players:
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
217 self.right_panel.add(player)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218 self.addClickListener(self)
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
219
284
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
220 help_msg = HTML("""- This radio plays Ogg Vorbis files.<br />
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
221 - What's that? I only know MP3!<br />
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
222 - Click <a style="color: red;">here</a> if you need some support :)
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
223 """)
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
224 help_msg.setStyleName('chatTextInfo-link')
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
225 help_msg.addClickListener(lambda: self._parent.host.bridge.call('joinMUC', None, DEFAULT_MUC, self._parent.nick))
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
226 self._parent.content.add(help_msg)
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
227
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
228 def pushNextSong(self, title):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
229 """Add a song to the left panel's next songs queue"""
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
230 next_song = Label(title)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
231 next_song.setStyleName("radiocol_next_song")
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
232 self.next_songs.append(next_song)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
233 self.left_panel.append(next_song)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
234
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
235 def popNextSong(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
236 """Remove the first song of next songs list
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
237 should be called when the song is played"""
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
238 #FIXME: should check that the song we remove is the one we play
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
239 next_song = self.next_songs.pop(0)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
240 self.left_panel.remove(next_song)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
241
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
242 def getQueueSize(self):
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
243 return len(self.left_panel.getChildren())
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
244
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
245 def radiocolPreload(self, filename, title, artist, album):
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
246 preloaded = False
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
247 for player in self.players:
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
248 if not player.filename or \
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
249 (player.played and player != self.current_player):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
250 #if player has no file loaded, or it has already played its song
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
251 #we use it to preload the next one
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
252 player.preload(filename, title, artist, album)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
253 preloaded = True
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
254 break
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
255 if not preloaded:
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
256 print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once")
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
257 else:
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
258 self.pushNextSong(title)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
259
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
260 def radiocolPlay(self, filename):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
261 for player in self.players:
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
262 if player.filename == filename:
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
263 player.play()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
264 self.popNextSong()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
265 self.current_player = player
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
266 self.control_panel.updateStatus()
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
267 return
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
268 print("WARNING: Song not found in queue, can't play it. This should not happen")
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
269
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
270 def radiocolNoUpload(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
271 self.control_panel.blockUpload()
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
272
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
273 def radiocolUploadOk(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
274 self.control_panel.unblockUpload()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
275
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
276 def radiocolSongRejected(self, reason):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
277 Window.alert("Song rejected: %s" % reason)