Mercurial > libervia-web
annotate browser_side/radiocol.py @ 394:ee61b0765d6c
browser_side: radiocol supports MP3
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 06 Mar 2014 01:06:19 +0100 |
parents | 30d03d9f07e4 |
children | 6148e9063069 |
rev | line source |
---|---|
127 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
340 | 5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org> |
127 | 6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
10 # (at your option) any later version. |
127 | 11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
15 # GNU Affero General Public License for more details. |
127 | 16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
127 | 19 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
20 import pyjd # this is dummy in pyjs |
127 | 21 from pyjamas.ui.VerticalPanel import VerticalPanel |
22 from pyjamas.ui.HorizontalPanel import HorizontalPanel | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
23 from pyjamas.ui.FlexTable import FlexTable |
127 | 24 from pyjamas.ui.FormPanel import FormPanel |
25 from pyjamas.ui.Label import Label | |
26 from pyjamas.ui.Button import Button | |
27 from pyjamas.ui.ClickListener import ClickHandler | |
128 | 28 from pyjamas.ui.Hidden import Hidden |
29 from pyjamas.ui.HTML import HTML | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
30 from pyjamas.ui.CaptionPanel import CaptionPanel |
341
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
31 from pyjamas.media.Audio import Audio |
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 |
370
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
341
diff
changeset
|
36 from html_tools import html_sanitize |
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
341
diff
changeset
|
37 from file_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 |
394
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
39 from sat.core.i18n import _ |
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") |
300
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
84 self.timer_on = False |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
85 self._parent = parent |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
86 vPanel = VerticalPanel() |
127 | 87 |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
88 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
|
89 ('video/ogg', '*.ogv', 'Ogg Vorbis Video'), |
394
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
90 ('application/ogg', '*.ogx', 'Ogg Vorbis Multiplex'), |
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
91 ('audio/mpeg', '*.mp3', 'MPEG-Layer 3')] |
301
5943eaa6f422
browser_side (plugin radiocol): set the upload limit to 10 MB instead of 5
souliane <souliane@mailoo.org>
parents:
300
diff
changeset
|
92 self.file_upload = FilterFileUpload("song", 10, types) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
93 vPanel.add(self.file_upload) |
127 | 94 |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
95 hPanel = HorizontalPanel() |
130 | 96 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick")) |
97 hPanel.add(self.upload_btn) | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
98 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
|
99 self.updateStatus() |
130 | 100 hPanel.add(self.status) |
394
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
101 #We need to know the filename and the referee |
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
102 self.filename_field = Hidden('filename', '') |
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
103 hPanel.add(self.filename_field) |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
104 referee_field = Hidden('referee', self._parent.referee) |
394
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
105 hPanel.add(self.filename_field) |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
106 hPanel.add(referee_field) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
107 vPanel.add(hPanel) |
127 | 108 |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
109 self.add(vPanel) |
127 | 110 self.addFormHandler(self) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
111 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
112 def updateStatus(self): |
300
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
113 if self.timer_on: |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
114 return |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
115 # 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 self.status.setStyleName('radiocol_status') |
127 | 127 |
128 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
|
129 if self.file_upload.check(): |
394
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
130 self.status.setText('[Submitting, please wait...]') |
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
131 self.filename_field.setValue(self.file_upload.getFilename()) |
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
132 if self.file_upload.getFilename().lower().endswith('.mp3'): |
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
133 self._parent._parent.host.showWarning('STATUS', 'For a better support, it is recommended to submit Ogg Vorbis file instead of MP3. You can convert your files easily, ask for help if needed!', 5000) |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
134 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
|
135 self.file_upload.setFilename("") |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
136 |
127 | 137 def onSubmit(self, event): |
138 pass | |
139 | |
130 | 140 def blockUpload(self): |
141 self.file_upload.setVisible(False) | |
142 self.upload_btn.setEnabled(False) | |
143 | |
144 def unblockUpload(self): | |
145 self.file_upload.setVisible(True) | |
146 self.upload_btn.setEnabled(True) | |
147 | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
148 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
|
149 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
|
150 self.status.setStyleName('radiocol_upload_status_%s' % style) |
300
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
151 self.timer_on = True |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
152 |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
153 def cb(): |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
154 self.timer_on = False |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
155 self.updateStatus() |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
156 |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
157 Timer(5000, cb) |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
158 |
127 | 159 def onSubmitComplete(self, event): |
160 result = event.getResults() | |
161 if result == "OK": | |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
162 # 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
|
163 self.setTemporaryStatus('[Your song has been submitted to the radio]', "ok") |
127 | 164 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
|
165 self.setTemporaryStatus('[Something went wrong during your song upload]', "ko") |
394
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
166 self._parent.radiocolSongRejected(_("The uploaded file has been rejected, only Ogg Vorbis and MP3 songs are accepted.")) |
300
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
167 # TODO: would be great to re-use the original Exception class and message |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
168 # but it is lost in the middle of the traceback and encapsulated within |
4f221f34bdc7
browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents:
287
diff
changeset
|
169 # a DBusException instance --> extract the data from the traceback? |
127 | 170 else: |
171 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
|
172 self.status.setText('') |
127 | 173 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
174 |
341
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
175 class Player(Audio): |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
176 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
177 def __init__(self, player_id, metadata_panel): |
341
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
178 Audio.__init__(self) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
179 self._id = player_id |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
180 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
|
181 self.timestamp = "" |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
182 self.title = "" |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
183 self.artist = "" |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
184 self.album = "" |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
185 self.filename = None |
341
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
186 self.played = False # True when the song is playing/has played, becomes False on preload |
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
187 self.setAutobuffer(True) |
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
188 self.setAutoplay(False) |
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
189 self.setVisible(False) |
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
190 |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
191 |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
192 def preload(self, timestamp, filename, title, artist, album): |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
193 """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
|
194 self.timestamp = timestamp |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
195 self.filename = filename |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
196 self.title = title |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
197 self.artist = artist |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
198 self.album = album |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
199 self.played = False |
341
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
200 self.setSrc("radiocol/%s" % html_sanitize(filename)) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
201 print "preloading %s in %s" % (title, self._id) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
202 |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
203 def play(self, play=True): |
341
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
204 """Play or pause the song |
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
205 @param play: set to True to play or to False to pause |
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
206 """ |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
207 if play: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
208 self.played = True |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
209 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
|
210 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
|
211 self.metadata.setAlbum(self.album) |
341
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
212 Audio.play(self) |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
213 else: |
341
31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
214 self.pause() |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
215 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
216 |
127 | 217 class RadioColPanel(HorizontalPanel, ClickHandler): |
218 | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
219 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
|
220 # 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
|
221 HorizontalPanel.__init__(self, Height="90px") |
127 | 222 ClickHandler.__init__(self) |
223 self._parent = parent | |
224 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
|
225 self.queue_data = queue_data |
127 | 226 self.setStyleName("radiocolPanel") |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
227 |
127 | 228 # Now we set up the layout |
229 self.metadata_panel = MetadataPanel() | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
230 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
|
231 self.playlist_panel = VerticalPanel() |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
232 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
|
233 self.control_panel = ControlPanel(self) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
234 self.add(CaptionPanel("Controls", self.control_panel)) |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
235 |
130 | 236 self.next_songs = [] |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
237 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
|
238 self.current_player = None |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
239 for player in self.players: |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
240 self.add(player) |
127 | 241 self.addClickListener(self) |
130 | 242 |
394
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
243 help_msg = HTML("""Accepted file formats: Ogg Vorbis (recommended), MP3.<br /> |
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
244 Please do not submit files that are protected by copyright.<br /> |
ee61b0765d6c
browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
245 Click <a style="color: red;">here</a> if you need some support :) |
284
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
246 """) |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 |
130 | 251 def pushNextSong(self, title): |
252 """Add a song to the left panel's next songs queue""" | |
253 next_song = Label(title) | |
254 next_song.setStyleName("radiocol_next_song") | |
255 self.next_songs.append(next_song) | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
256 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
|
257 self.control_panel.updateStatus() |
130 | 258 |
259 def popNextSong(self): | |
260 """Remove the first song of next songs list | |
261 should be called when the song is played""" | |
262 #FIXME: should check that the song we remove is the one we play | |
263 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
|
264 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
|
265 self.control_panel.updateStatus() |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
266 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
267 def getQueueSize(self): |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
268 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
|
269 |
287
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
270 def radiocolCheckPreload(self, timestamp): |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
271 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
|
272 if player.timestamp == timestamp: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
273 return False |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
274 return True |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
275 |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
276 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
|
277 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
|
278 return # song already preloaded |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
279 preloaded = False |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
280 for player in self.players: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
281 if not player.filename or \ |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
282 (player.played and player != self.current_player): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
283 #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
|
284 #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
|
285 player.preload(timestamp, filename, title, artist, album) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
286 preloaded = True |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
287 break |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
288 if not preloaded: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
289 print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once") |
130 | 290 else: |
291 self.pushNextSong(title) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
292 |
130 | 293 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
|
294 found = False |
130 | 295 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
|
296 if not found and player.filename == filename: |
130 | 297 player.play() |
298 self.popNextSong() | |
299 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
|
300 found = True |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
301 else: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
302 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
|
303 if not found: |
7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents:
286
diff
changeset
|
304 print("WARNING: Song not found in queue, can't play it. This should not happen") |
127 | 305 |
130 | 306 def radiocolNoUpload(self): |
307 self.control_panel.blockUpload() | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
308 |
130 | 309 def radiocolUploadOk(self): |
310 self.control_panel.unblockUpload() | |
311 | |
312 def radiocolSongRejected(self, reason): | |
313 Window.alert("Song rejected: %s" % reason) |