Mercurial > libervia-web
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 |
rev | line source |
---|---|
127 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
165 | 6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org> |
127 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
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 | 23 from pyjamas.ui.VerticalPanel import VerticalPanel |
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 | 26 from pyjamas.ui.FormPanel import FormPanel |
27 from pyjamas.ui.Label import Label | |
28 from pyjamas.ui.Button import Button | |
29 from pyjamas.ui.ClickListener import ClickHandler | |
128 | 30 from pyjamas.ui.Hidden import Hidden |
31 from pyjamas.ui.HTML import HTML | |
127 | 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 | 35 |
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 | 39 |
40 | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
41 class MetadataPanel(FlexTable): |
127 | 42 |
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 | 73 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
74 |
127 | 75 class ControlPanel(FormPanel): |
76 """Panel used to show controls to add a song, or vote for the current one""" | |
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 | 79 FormPanel.__init__(self) |
80 self.setEncoding(FormPanel.ENCODING_MULTIPART) | |
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 | 84 |
85 hPanel = HorizontalPanel() | |
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 | 91 hPanel.add(self.file_upload) |
127 | 92 |
130 | 93 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick")) |
94 hPanel.add(self.upload_btn) | |
127 | 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 | 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 | 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 | 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 | 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 | 121 |
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 | 128 def onSubmit(self, event): |
129 pass | |
130 | |
130 | 131 def blockUpload(self): |
132 self.file_upload.setVisible(False) | |
133 self.upload_btn.setEnabled(False) | |
134 | |
135 def unblockUpload(self): | |
136 self.file_upload.setVisible(True) | |
137 self.upload_btn.setEnabled(True) | |
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 | 144 def onSubmitComplete(self, event): |
145 result = event.getResults() | |
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 | 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 | 150 else: |
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 | 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 | 190 class RadioColPanel(HorizontalPanel, ClickHandler): |
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 | 193 HorizontalPanel.__init__(self) |
194 ClickHandler.__init__(self) | |
195 self._parent = parent | |
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 | 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 | 201 # Now we set up the layout |
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 | 205 self.add(self.left_panel) |
128 | 206 self.right_panel = VerticalPanel() |
127 | 207 self.metadata_panel = MetadataPanel() |
128 | 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 | 210 self.right_panel.add(self.control_panel) |
127 | 211 self.add(self.right_panel) |
128 | 212 #self.right_panel.setBorderWidth(1) |
130 | 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 | 218 self.addClickListener(self) |
130 | 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 | 228 def pushNextSong(self, title): |
229 """Add a song to the left panel's next songs queue""" | |
230 next_song = Label(title) | |
231 next_song.setStyleName("radiocol_next_song") | |
232 self.next_songs.append(next_song) | |
233 self.left_panel.append(next_song) | |
234 | |
235 def popNextSong(self): | |
236 """Remove the first song of next songs list | |
237 should be called when the song is played""" | |
238 #FIXME: should check that the song we remove is the one we play | |
239 next_song = self.next_songs.pop(0) | |
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 | 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 | 257 else: |
258 self.pushNextSong(title) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
259 |
130 | 260 def radiocolPlay(self, filename): |
261 for player in self.players: | |
262 if player.filename == filename: | |
263 player.play() | |
264 self.popNextSong() | |
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 | 267 return |
268 print("WARNING: Song not found in queue, can't play it. This should not happen") | |
127 | 269 |
130 | 270 def radiocolNoUpload(self): |
271 self.control_panel.blockUpload() | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
272 |
130 | 273 def radiocolUploadOk(self): |
274 self.control_panel.unblockUpload() | |
275 | |
276 def radiocolSongRejected(self, reason): | |
277 Window.alert("Song rejected: %s" % reason) |