annotate browser/sat_browser/game_radiocol.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/browser/sat_browser/game_radiocol.py@f2170536ba23
children 2af117bfe6cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 301
diff changeset
4 # Libervia: a Salut à Toi frontend
1054
f2170536ba23 date update
Goffi <goffi@goffi.org>
parents: 964
diff changeset
5 # Copyright (C) 2011-2018 Jérôme Poisson <goffi@goffi.org>
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 422
diff changeset
21 from sat.core.log import getLogger
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 422
diff changeset
22 log = getLogger(__name__)
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 481
diff changeset
23
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
24 from sat.core.i18n import _, D_
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
25 from sat_frontends.tools import host_listener
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 467
diff changeset
26 from constants import Const as C
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 439
diff changeset
27
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.VerticalPanel import VerticalPanel
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.HorizontalPanel import HorizontalPanel
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
30 from pyjamas.ui.FlexTable import FlexTable
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas.ui.FormPanel import FormPanel
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from pyjamas.ui.Label import Label
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from pyjamas.ui.Button import Button
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from pyjamas.ui.ClickListener import ClickHandler
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
35 from pyjamas.ui.Hidden import Hidden
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
36 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
37 from pyjamas.media.Audio import Audio
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 from pyjamas import Window
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
39 from pyjamas.Timer import Timer
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
41 import html_tools
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
42 import file_tools
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
43 import dialog
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45
684
e876f493dccc browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents: 676
diff changeset
46 unicode = str # XXX: pyjama doesn't manage unicode
e876f493dccc browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents: 676
diff changeset
47
e876f493dccc browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents: 676
diff changeset
48
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
49 class MetadataPanel(FlexTable):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def __init__(self):
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
52 FlexTable.__init__(self)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
53 title_lbl = Label("title:")
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
54 title_lbl.setStyleName('radiocol_metadata_lbl')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
55 artist_lbl = Label("artist:")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
56 artist_lbl.setStyleName('radiocol_metadata_lbl')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
57 album_lbl = Label("album:")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
58 album_lbl.setStyleName('radiocol_metadata_lbl')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
59 self.title = Label("")
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
60 self.title.setStyleName('radiocol_metadata')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
61 self.artist = Label("")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
62 self.artist.setStyleName('radiocol_metadata')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
63 self.album = Label("")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
64 self.album.setStyleName('radiocol_metadata')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
65 self.setWidget(0, 0, title_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
66 self.setWidget(1, 0, artist_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
67 self.setWidget(2, 0, album_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
68 self.setWidget(0, 1, self.title)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
69 self.setWidget(1, 1, self.artist)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
70 self.setWidget(2, 1, self.album)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
71 self.setStyleName("radiocol_metadata_pnl")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
72
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
73 def setTitle(self, title):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
74 self.title.setText(title)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
75
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
76 def setArtist(self, artist):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
77 self.artist.setText(artist)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
78
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
79 def setAlbum(self, album):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
80 self.album.setText(album)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
82
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 class ControlPanel(FormPanel):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 """Panel used to show controls to add a song, or vote for the current one"""
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
86 def __init__(self, parent):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 FormPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.setEncoding(FormPanel.ENCODING_MULTIPART)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.setMethod(FormPanel.METHOD_POST)
151
a159cc29b556 server side: file upload is now more generic:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
90 self.setAction("upload_radiocol")
300
4f221f34bdc7 browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents: 287
diff changeset
91 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
92 self._parent = parent
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
93 vPanel = VerticalPanel()
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 275
diff changeset
95 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
96 ('video/ogg', '*.ogv', 'Ogg Vorbis Video'),
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
97 ('application/ogg', '*.ogx', 'Ogg Vorbis Multiplex'),
398
462fc3359ee3 browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
souliane <souliane@mailoo.org>
parents: 397
diff changeset
98 ('audio/mpeg', '*.mp3', 'MPEG-Layer 3'),
462fc3359ee3 browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
souliane <souliane@mailoo.org>
parents: 397
diff changeset
99 ('audio/mp3', '*.mp3', 'MPEG-Layer 3'),
462fc3359ee3 browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
souliane <souliane@mailoo.org>
parents: 397
diff changeset
100 ]
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
101 self.file_upload = file_tools.FilterFileUpload("song", 10, types)
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
102 vPanel.add(self.file_upload)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
104 hPanel = HorizontalPanel()
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
105 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick"))
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
106 hPanel.add(self.upload_btn)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
107 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
108 self.updateStatus()
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
109 hPanel.add(self.status)
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
110 #We need to know the filename and the referee
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
111 self.filename_field = Hidden('filename', '')
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
112 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
113 referee_field = Hidden('referee', self._parent.referee)
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
114 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
115 hPanel.add(referee_field)
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
116 vPanel.add(hPanel)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
118 self.add(vPanel)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.addFormHandler(self)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
120
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
121 def updateStatus(self):
300
4f221f34bdc7 browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents: 287
diff changeset
122 if self.timer_on:
4f221f34bdc7 browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents: 287
diff changeset
123 return
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
124 # 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 self.status.setStyleName('radiocol_status')
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 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
138 if self.file_upload.check():
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
139 self.status.setText('[Submitting, please wait...]')
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
140 self.filename_field.setValue(self.file_upload.getFilename())
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
141 if self.file_upload.getFilename().lower().endswith('.mp3'):
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
142 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
143 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
144 self.file_upload.setFilename("")
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
145
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 def onSubmit(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 pass
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
149 def blockUpload(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
150 self.file_upload.setVisible(False)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
151 self.upload_btn.setEnabled(False)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
152
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
153 def unblockUpload(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
154 self.file_upload.setVisible(True)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
155 self.upload_btn.setEnabled(True)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
156
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
157 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
158 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
159 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
160 self.timer_on = True
4f221f34bdc7 browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents: 287
diff changeset
161
422
20c508f9b32a browser side: fixed bad use of Timer
Goffi <goffi@goffi.org>
parents: 398
diff changeset
162 def cb(timer):
300
4f221f34bdc7 browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents: 287
diff changeset
163 self.timer_on = False
4f221f34bdc7 browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents: 287
diff changeset
164 self.updateStatus()
4f221f34bdc7 browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents: 287
diff changeset
165
4f221f34bdc7 browser_side (plugins radiocol, xep-0054): handle upload errors
souliane <souliane@mailoo.org>
parents: 287
diff changeset
166 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
167
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 def onSubmitComplete(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 result = event.getResults()
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 467
diff changeset
170 if result == C.UPLOAD_OK:
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
171 # 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
172 self.setTemporaryStatus('[Your song has been submitted to the radio]', "ok")
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 467
diff changeset
173 elif result == C.UPLOAD_KO:
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
174 self.setTemporaryStatus('[Something went wrong during your song upload]', "ko")
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 481
diff changeset
175 self._parent.radiocolSongRejectedHandler(_("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
176 # 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
177 # 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
178 # a DBusException instance --> extract the data from the traceback?
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 else:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 467
diff changeset
180 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
181 self.status.setText('')
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
183
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
184 class Player(Audio):
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
185
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
186 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
187 Audio.__init__(self)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
188 self._id = player_id
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
189 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
190 self.timestamp = ""
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
191 self.title = ""
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
192 self.artist = ""
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
193 self.album = ""
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
194 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
195 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
196 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
197 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
198 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
199
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
200 def preload(self, timestamp, filename, title, artist, album):
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
201 """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
202 self.timestamp = timestamp
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
203 self.filename = filename
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
204 self.title = title
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
205 self.artist = artist
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
206 self.album = album
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
207 self.played = False
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
208 self.setSrc(u"radiocol/%s" % html_tools.html_sanitize(filename))
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
209 log.debug(u"preloading %s in %s" % (title, self._id))
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
210
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
211 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
212 """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
213 @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
214 """
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
215 if play:
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
216 self.played = True
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
217 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
218 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
219 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
220 Audio.play(self)
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
221 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
222 self.pause()
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
223
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
224
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
225 class RadioColPanel(HorizontalPanel, ClickHandler):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
226
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 481
diff changeset
227 def __init__(self, parent, referee, players, queue_data):
397
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 394
diff changeset
228 """
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 394
diff changeset
229 @param parent
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 394
diff changeset
230 @param referee
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 394
diff changeset
231 @param players
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 394
diff changeset
232 @param queue_data: list of integers (queue to start, queue limit)
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 394
diff changeset
233 """
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
234 # 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
235 HorizontalPanel.__init__(self, Height="90px")
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
236 ClickHandler.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
237 self._parent = parent
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
238 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
239 self.queue_data = queue_data
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
240 self.setStyleName("radiocolPanel")
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
241
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
242 # Now we set up the layout
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
243 self.metadata_panel = MetadataPanel()
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
244 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
245 self.playlist_panel = VerticalPanel()
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
246 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
247 self.control_panel = ControlPanel(self)
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
248 self.add(CaptionPanel("Controls", self.control_panel))
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
249
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
250 self.next_songs = []
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
251 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
252 self.current_player = None
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
253 for player in self.players:
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
254 self.add(player)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
255 self.addClickListener(self)
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
256
397
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 394
diff changeset
257 help_msg = """Accepted file formats: Ogg Vorbis (recommended), MP3.<br />
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 370
diff changeset
258 Please do not submit files that are protected by copyright.<br />
397
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 394
diff changeset
259 Click <a style="color: red;">here</a> if you need some support :)"""
839
09ace5cbcb9b browser (games, menu): rename showFailureRoomInvalid to onJoinMUCFailure and display a nice message when the room has already been joined (it is not a real error)
souliane <souliane@mailoo.org>
parents: 818
diff changeset
260 link_cb = lambda: self._parent.host.bridge.joinMUC(self._parent.host.default_muc, self._parent.nick, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=self._parent.host.onJoinMUCFailure)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 839
diff changeset
261 # FIXME: printInfo disabled after refactoring
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 839
diff changeset
262 # self._parent.printInfo(help_msg, type_='link', link_cb=link_cb)
284
bee4719af9b9 browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents: 283
diff changeset
263
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
264 def pushNextSong(self, title):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
265 """Add a song to the left panel's next songs queue"""
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
266 next_song = Label(title)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
267 next_song.setStyleName("radiocol_next_song")
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
268 self.next_songs.append(next_song)
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
269 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
270 self.control_panel.updateStatus()
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
271
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
272 def popNextSong(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
273 """Remove the first song of next songs list
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
274 should be called when the song is played"""
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
275 #FIXME: should check that the song we remove is the one we play
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
276 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
277 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
278 self.control_panel.updateStatus()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
279
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 284
diff changeset
280 def getQueueSize(self):
286
e76ec07be8e5 browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents: 285
diff changeset
281 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
282
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
283 def radiocolCheckPreload(self, timestamp):
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
284 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
285 if player.timestamp == timestamp:
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
286 return False
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
287 return True
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
288
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 481
diff changeset
289 def radiocolPreloadHandler(self, timestamp, filename, title, artist, album, sender):
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
290 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
291 return # song already preloaded
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
292 preloaded = False
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
293 for player in self.players:
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
294 if not player.filename or \
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
295 (player.played and player != self.current_player):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
296 #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
297 #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
298 player.preload(timestamp, filename, title, artist, album)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
299 preloaded = True
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
300 break
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
301 if not preloaded:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 422
diff changeset
302 log.warning("Can't preload song, we are getting too many songs to preload, we shouldn't have more than %d at once" % self.queue_data[1])
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
303 else:
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
304 self.pushNextSong(title)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 839
diff changeset
305 # FIXME: printInfo disabled after refactoring
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 839
diff changeset
306 # self._parent.printInfo(_('%(user)s uploaded %(artist)s - %(title)s') % {'user': sender, 'artist': artist, 'title': title})
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
307
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 481
diff changeset
308 def radiocolPlayHandler(self, filename):
287
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
309 found = False
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
310 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
311 if not found and player.filename == filename:
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
312 player.play()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
313 self.popNextSong()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
314 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
315 found = True
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
316 else:
7a1dc69112b8 browser_side (plugin radiocol): send the current queue to new players
souliane <souliane@mailoo.org>
parents: 286
diff changeset
317 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
318 if not found:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 422
diff changeset
319 log.error("Song not found in queue, can't play it. This should not happen")
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
320
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 481
diff changeset
321 def radiocolNoUploadHandler(self):
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
322 self.control_panel.blockUpload()
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
323
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 481
diff changeset
324 def radiocolUploadOkHandler(self):
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
325 self.control_panel.unblockUpload()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
326
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 481
diff changeset
327 def radiocolSongRejectedHandler(self, reason):
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
328 Window.alert("Song rejected: %s" % reason)
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
329
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
330
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
331 ## Menu
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
332
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
333 def hostReady(host):
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
334 def onCollectiveRadio(self):
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
335 def callback(room_jid, contacts):
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
336 contacts = [unicode(contact) for contact in contacts]
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
337 room_jid_s = unicode(room_jid) if room_jid else ''
839
09ace5cbcb9b browser (games, menu): rename showFailureRoomInvalid to onJoinMUCFailure and display a nice message when the room has already been joined (it is not a real error)
souliane <souliane@mailoo.org>
parents: 818
diff changeset
338 host.bridge.launchRadioCollective(contacts, room_jid_s, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=host.onJoinMUCFailure)
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
339 dialog.RoomAndContactsChooser(host, callback, ok_button="Choose", title="Collective Radio", visible=(False, True))
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
340
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
341
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
342 def gotMenus():
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
343 host.menus.addMenu(C.MENU_GLOBAL, (D_(u"Groups"), D_(u"Collective radio")), callback=onCollectiveRadio)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
344
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
345 host.addListener('gotMenus', gotMenus)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
346
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
347 host_listener.addListener(hostReady)