Mercurial > libervia-web
annotate browser_side/radiocol.py @ 283:0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 25 Nov 2013 20:39:28 +0100 |
parents | a763b2ac5d41 |
children | bee4719af9b9 |
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 | |
25 from pyjamas.ui.SimplePanel import SimplePanel | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
26 from pyjamas.ui.FlexTable import FlexTable |
127 | 27 from pyjamas.ui.FormPanel import FormPanel |
28 from pyjamas.ui.NamedFrame import NamedFrame | |
29 from pyjamas.ui.Label import Label | |
30 from pyjamas.ui.Button import Button | |
31 from pyjamas.ui.ClickListener import ClickHandler | |
32 from pyjamas.ui.MouseListener import MouseHandler | |
128 | 33 from pyjamas.ui.Hidden import Hidden |
34 from pyjamas.ui.HTML import HTML | |
127 | 35 from pyjamas import Window |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
36 from pyjamas.Timer import Timer |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
37 from __pyjamas__ import JS |
127 | 38 |
39 from jid import JID | |
40 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
|
41 from tools import FilterFileUpload |
127 | 42 |
43 | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
44 class MetadataPanel(FlexTable): |
127 | 45 |
46 def __init__(self): | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
47 FlexTable.__init__(self) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
48 title_lbl = Label("title:") |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
49 title_lbl.setStyleName('radiocol_metadata_lbl') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
50 artist_lbl = Label("artist:") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
51 artist_lbl.setStyleName('radiocol_metadata_lbl') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
52 album_lbl = Label("album:") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
53 album_lbl.setStyleName('radiocol_metadata_lbl') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
54 self.title = Label("") |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
55 self.title.setStyleName('radiocol_metadata') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
56 self.artist = Label("") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
57 self.artist.setStyleName('radiocol_metadata') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
58 self.album = Label("") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
59 self.album.setStyleName('radiocol_metadata') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
60 self.setWidget(0, 0, title_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
61 self.setWidget(1, 0, artist_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
62 self.setWidget(2, 0, album_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
63 self.setWidget(0, 1, self.title) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
64 self.setWidget(1, 1, self.artist) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
65 self.setWidget(2, 1, self.album) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
66 self.setStyleName("radiocol_metadata_pnl") |
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 setTitle(self, title): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
69 self.title.setText(title) |
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 setArtist(self, artist): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
72 self.artist.setText(artist) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
73 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
74 def setAlbum(self, album): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
75 self.album.setText(album) |
127 | 76 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
77 |
127 | 78 class ControlPanel(FormPanel): |
79 """Panel used to show controls to add a song, or vote for the current one""" | |
80 | |
128 | 81 def __init__(self, referee): |
127 | 82 FormPanel.__init__(self) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
83 self._timer = Timer(notify=self._timeCb) |
127 | 84 self.setEncoding(FormPanel.ENCODING_MULTIPART) |
85 self.setMethod(FormPanel.METHOD_POST) | |
151
a159cc29b556
server side: file upload is now more generic:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
86 self.setAction("upload_radiocol") |
127 | 87 vPanel = VerticalPanel() |
88 | |
89 hPanel = HorizontalPanel() | |
90 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
|
91 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
|
92 ('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
|
93 ('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
|
94 self.file_upload = FilterFileUpload("song", 5, types) |
130 | 95 hPanel.add(self.file_upload) |
127 | 96 |
130 | 97 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick")) |
98 hPanel.add(self.upload_btn) | |
127 | 99 |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
100 self.status = Label() |
130 | 101 hPanel.add(self.status) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
102 |
127 | 103 vPanel.add(hPanel) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
104 |
128 | 105 #We need to know the referee |
106 referee_field = Hidden('referee', referee) | |
107 vPanel.add(referee_field) | |
127 | 108 |
109 self.add(vPanel) | |
110 self.addFormHandler(self) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
111 |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
112 def _timeCb(self, timer): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
113 self.status.setText('') |
127 | 114 |
115 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
|
116 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
|
117 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
|
118 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
|
119 self.status.setText('[Submitting, please wait...]') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
120 |
127 | 121 def onSubmit(self, event): |
122 pass | |
123 | |
130 | 124 def blockUpload(self): |
125 self.file_upload.setVisible(False) | |
126 self.upload_btn.setEnabled(False) | |
127 | |
128 def unblockUpload(self): | |
129 self.file_upload.setVisible(True) | |
130 self.upload_btn.setEnabled(True) | |
131 | |
127 | 132 def onSubmitComplete(self, event): |
133 result = event.getResults() | |
134 if result == "OK": | |
130 | 135 self.status.setText('[Your song has been added to queue]') |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
136 self.status.setStyleName('radiocol_upload_status_ok') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
137 self._timer.schedule(5000) |
127 | 138 elif result == "KO": |
130 | 139 self.status.setText('[Something went wrong during your song upload]') |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
140 self.status.setStyleName('radiocol_upload_status_ko') |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
141 self._timer.schedule(5000) |
127 | 142 else: |
143 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
|
144 self.status.setText('') |
127 | 145 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
146 |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
147 class Player(HTML): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
148 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
149 def __init__(self, player_id, metadata_panel): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
150 HTML.__init__(self) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
151 self._id = player_id |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
152 self.metadata = metadata_panel |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
153 self.title = "" |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
154 self.artist = "" |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
155 self.album = "" |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
156 self.filename = None |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
157 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
|
158 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
159 def preload(self, filename, title, artist, album): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
160 """preload the song but doesn't play it""" |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
161 self.filename = filename |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
162 self.title = title |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
163 self.artist = artist |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
164 self.album = album |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
165 self.played = False |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
166 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
|
167 print "preloading %s in %s" % (title, self._id) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
168 |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
169 def play(self): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
170 """actually play the song""" |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
171 self.played = True |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
172 self.metadata.setTitle(self.title) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
173 self.metadata.setArtist(self.artist) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
174 self.metadata.setAlbum(self.album) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
175 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
176 JS(""" |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
177 var player = top.document.getElementById(this._id); |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
178 player.play(); |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
179 """) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
180 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
181 |
127 | 182 class RadioColPanel(HorizontalPanel, ClickHandler): |
183 | |
275
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
243
diff
changeset
|
184 def __init__(self, parent, referee, player_nick, players=None): |
127 | 185 HorizontalPanel.__init__(self) |
186 ClickHandler.__init__(self) | |
187 self._parent = parent | |
188 self.referee = referee | |
189 self.setStyleName("radiocolPanel") | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
190 self.setHeight('30%') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
191 |
127 | 192 # Now we set up the layout |
193 self.left_panel = VerticalPanel() | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
194 self.left_panel.setStyleName("radiocol_left_panel") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
195 self.left_panel.setHeight('100%') |
127 | 196 self.add(self.left_panel) |
128 | 197 self.right_panel = VerticalPanel() |
127 | 198 self.metadata_panel = MetadataPanel() |
128 | 199 self.right_panel.add(self.metadata_panel) |
200 self.control_panel = ControlPanel(self.referee) | |
201 self.right_panel.add(self.control_panel) | |
127 | 202 self.add(self.right_panel) |
128 | 203 #self.right_panel.setBorderWidth(1) |
130 | 204 self.next_songs = [] |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
205 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
|
206 self.current_player = None |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
207 for player in self.players: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
208 self.right_panel.add(player) |
127 | 209 self.addClickListener(self) |
130 | 210 |
211 def pushNextSong(self, title): | |
212 """Add a song to the left panel's next songs queue""" | |
213 next_song = Label(title) | |
214 next_song.setStyleName("radiocol_next_song") | |
215 self.next_songs.append(next_song) | |
216 self.left_panel.append(next_song) | |
217 | |
218 def popNextSong(self): | |
219 """Remove the first song of next songs list | |
220 should be called when the song is played""" | |
221 #FIXME: should check that the song we remove is the one we play | |
222 next_song = self.next_songs.pop(0) | |
223 self.left_panel.remove(next_song) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
224 |
128 | 225 def radiocolPreload(self, filename, title, artist, album): |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
226 preloaded = False |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
227 for player in self.players: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
228 if not player.filename or \ |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
229 (player.played and player != self.current_player): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
230 #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
|
231 #we use it to preload the next one |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
232 player.preload(filename, title, artist, album) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
233 preloaded = True |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
234 break |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
235 if not preloaded: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
236 print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once") |
130 | 237 else: |
238 self.pushNextSong(title) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
239 |
130 | 240 def radiocolPlay(self, filename): |
241 for player in self.players: | |
242 if player.filename == filename: | |
243 player.play() | |
244 self.popNextSong() | |
245 self.current_player = player | |
246 return | |
247 print("WARNING: Song not found in queue, can't play it. This should not happen") | |
127 | 248 |
130 | 249 def radiocolNoUpload(self): |
250 self.control_panel.blockUpload() | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
251 |
130 | 252 def radiocolUploadOk(self): |
253 self.control_panel.unblockUpload() | |
254 | |
255 def radiocolSongRejected(self, reason): | |
256 Window.alert("Song rejected: %s" % reason) |