Mercurial > libervia-web
annotate browser_side/radiocol.py @ 297:19bcd39c77f6
server side: sendMessage is now async
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 Dec 2013 01:36:57 +0100 |
parents | 7a1dc69112b8 |
children | 4f221f34bdc7 |
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 | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
32 from pyjamas.ui.CaptionPanel import CaptionPanel |
127 | 33 from pyjamas import Window |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
34 from pyjamas.Timer import Timer |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
35 from __pyjamas__ import JS |
127 | 36 |
37 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
|
38 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
|
39 from sat_frontends.tools.misc import DEFAULT_MUC |
127 | 40 |
41 | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
42 class MetadataPanel(FlexTable): |
127 | 43 |
44 def __init__(self): | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
45 FlexTable.__init__(self) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
46 title_lbl = Label("title:") |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
47 title_lbl.setStyleName('radiocol_metadata_lbl') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
48 artist_lbl = Label("artist:") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
49 artist_lbl.setStyleName('radiocol_metadata_lbl') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
50 album_lbl = Label("album:") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
51 album_lbl.setStyleName('radiocol_metadata_lbl') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
52 self.title = Label("") |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
53 self.title.setStyleName('radiocol_metadata') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
54 self.artist = Label("") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
55 self.artist.setStyleName('radiocol_metadata') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
56 self.album = Label("") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
57 self.album.setStyleName('radiocol_metadata') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
58 self.setWidget(0, 0, title_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
59 self.setWidget(1, 0, artist_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
60 self.setWidget(2, 0, album_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
61 self.setWidget(0, 1, self.title) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
62 self.setWidget(1, 1, self.artist) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
63 self.setWidget(2, 1, self.album) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
64 self.setStyleName("radiocol_metadata_pnl") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
65 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
66 def setTitle(self, title): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
67 self.title.setText(title) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
68 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
69 def setArtist(self, artist): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
70 self.artist.setText(artist) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
71 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
72 def setAlbum(self, album): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
73 self.album.setText(album) |
127 | 74 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
75 |
127 | 76 class ControlPanel(FormPanel): |
77 """Panel used to show controls to add a song, or vote for the current one""" | |
78 | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
79 def __init__(self, parent): |
127 | 80 FormPanel.__init__(self) |
81 self.setEncoding(FormPanel.ENCODING_MULTIPART) | |
82 self.setMethod(FormPanel.METHOD_POST) | |
151
a159cc29b556
server side: file upload is now more generic:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
83 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
|
84 self._parent = parent |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
85 vPanel = VerticalPanel() |
127 | 86 |
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) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
91 vPanel.add(self.file_upload) |
127 | 92 |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
93 hPanel = HorizontalPanel() |
130 | 94 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick")) |
95 hPanel.add(self.upload_btn) | |
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) |
128 | 99 #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
|
100 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
|
101 hPanel.add(referee_field) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
102 vPanel.add(hPanel) |
127 | 103 |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
104 self.add(vPanel) |
127 | 105 self.addFormHandler(self) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
106 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
107 def updateStatus(self): |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
108 # 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 self.status.setStyleName('radiocol_status') |
127 | 120 |
121 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
|
122 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
|
123 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
|
124 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
|
125 self.status.setText('[Submitting, please wait...]') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
126 |
127 | 127 def onSubmit(self, event): |
128 pass | |
129 | |
130 | 130 def blockUpload(self): |
131 self.file_upload.setVisible(False) | |
132 self.upload_btn.setEnabled(False) | |
133 | |
134 def unblockUpload(self): | |
135 self.file_upload.setVisible(True) | |
136 self.upload_btn.setEnabled(True) | |
137 | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 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
|
142 |
127 | 143 def onSubmitComplete(self, event): |
144 result = event.getResults() | |
145 if result == "OK": | |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
146 # the song can still be rejected (not readable, full queue...) |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
147 self.setTemporaryStatus('[Your song has been submitted to the radio]', "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 |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
161 self.timestamp = "" |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
162 self.title = "" |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
163 self.artist = "" |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
164 self.album = "" |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
165 self.filename = None |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
166 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
|
167 |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
168 def preload(self, timestamp, filename, title, artist, album): |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
169 """preload the song but doesn't play it""" |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
170 self.timestamp = timestamp |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
171 self.filename = filename |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
172 self.title = title |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
173 self.artist = artist |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
174 self.album = album |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
175 self.played = False |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
176 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
|
177 print "preloading %s in %s" % (title, self._id) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
178 |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
179 def play(self, play=True): |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
180 """actually play the song""" |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
181 if play: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
182 self.played = True |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
183 self.metadata.setTitle(self.title) |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
184 self.metadata.setArtist(self.artist) |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
185 self.metadata.setAlbum(self.album) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
186 |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
187 if play: # JS only support constant strings |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
188 JS("""var player = top.document.getElementById(this._id); if (player) player.play();""") |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
189 else: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
190 JS("""var player = top.document.getElementById(this._id); if (player) player.pause();""") |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
191 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
192 |
127 | 193 class RadioColPanel(HorizontalPanel, ClickHandler): |
194 | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
195 def __init__(self, parent, referee, player_nick, players, queue_data): |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
196 # We need to set it here and not in the CSS :( |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
197 HorizontalPanel.__init__(self, Height="90px") |
127 | 198 ClickHandler.__init__(self) |
199 self._parent = parent | |
200 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
|
201 self.queue_data = queue_data |
127 | 202 self.setStyleName("radiocolPanel") |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
203 |
127 | 204 # Now we set up the layout |
205 self.metadata_panel = MetadataPanel() | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
206 self.add(CaptionPanel("Now playing", self.metadata_panel)) |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
207 self.playlist_panel = VerticalPanel() |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
208 self.add(CaptionPanel("Songs queue", self.playlist_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) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
210 self.add(CaptionPanel("Controls", self.control_panel)) |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
211 |
130 | 212 self.next_songs = [] |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
213 self.players = [Player("player_%d" % i, self.metadata_panel) for i in xrange(queue_data[1] + 1)] |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
214 self.current_player = None |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
215 for player in self.players: |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
216 self.add(player) |
127 | 217 self.addClickListener(self) |
130 | 218 |
284
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
219 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
|
220 - 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
|
221 - 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
|
222 """) |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
223 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
|
224 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
|
225 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
|
226 |
130 | 227 def pushNextSong(self, title): |
228 """Add a song to the left panel's next songs queue""" | |
229 next_song = Label(title) | |
230 next_song.setStyleName("radiocol_next_song") | |
231 self.next_songs.append(next_song) | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
232 self.playlist_panel.append(next_song) |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
233 self.control_panel.updateStatus() |
130 | 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) | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
240 self.playlist_panel.remove(next_song) |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
241 self.control_panel.updateStatus() |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
242 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
243 def getQueueSize(self): |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
244 return len(self.playlist_panel.getChildren()) |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
245 |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
246 def radiocolCheckPreload(self, timestamp): |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
247 for player in self.players: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
248 if player.timestamp == timestamp: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
249 return False |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
250 return True |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
251 |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
252 def radiocolPreload(self, timestamp, filename, title, artist, album): |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
253 if not self.radiocolCheckPreload(timestamp): |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
254 return # song already preloaded |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
255 preloaded = False |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
256 for player in self.players: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
257 if not player.filename or \ |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
258 (player.played and player != self.current_player): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
259 #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
|
260 #we use it to preload the next one |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
261 player.preload(timestamp, filename, title, artist, album) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
262 preloaded = True |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
263 break |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
264 if not preloaded: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
265 print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once") |
130 | 266 else: |
267 self.pushNextSong(title) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
268 |
130 | 269 def radiocolPlay(self, filename): |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
270 found = False |
130 | 271 for player in self.players: |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
272 if not found and player.filename == filename: |
130 | 273 player.play() |
274 self.popNextSong() | |
275 self.current_player = player | |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
276 found = True |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
277 else: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
278 player.play(False) # in case the previous player was not sync |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
279 if not found: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
280 print("WARNING: Song not found in queue, can't play it. This should not happen") |
127 | 281 |
130 | 282 def radiocolNoUpload(self): |
283 self.control_panel.blockUpload() | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
284 |
130 | 285 def radiocolUploadOk(self): |
286 self.control_panel.unblockUpload() | |
287 | |
288 def radiocolSongRejected(self, reason): | |
289 Window.alert("Song rejected: %s" % reason) |