changeset 394:ee61b0765d6c

browser_side: radiocol supports MP3
author souliane <souliane@mailoo.org>
date Thu, 06 Mar 2014 01:06:19 +0100
parents a3d58514a4d0
children 98cd5387d291
files browser_side/panels.py browser_side/radiocol.py libervia_server/__init__.py
diffstat 3 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Wed Mar 05 21:42:03 2014 +0100
+++ b/browser_side/panels.py	Thu Mar 06 01:06:19 2014 +0100
@@ -291,7 +291,7 @@
         self._popup = None
         self._timer = Timer(notify=self._timeCb)
 
-    def showWarning(self, type_=None, msg=None):
+    def showWarning(self, type_=None, msg=None, duration=2000):
         """Display a popup information message, e.g. to notify the recipient of a message being composed.
         If type_ is None, a popup being currently displayed will be hidden.
         @type_: a type determining the CSS style to be applied (see __showWarning)
@@ -306,7 +306,7 @@
             self._timeCb(None)  # we remove the popup
             self.__showWarning(type_, msg)
 
-        self._timer.schedule(2000)
+        self._timer.schedule(duration)
 
     def __showWarning(self, type_, msg):
         """Display a popup information message, e.g. to notify the recipient of a message being composed.
@@ -324,7 +324,6 @@
         elif type_ == "GROUP":
             style = "targetGroup"
         elif type_ == "STATUS":
-            msg = "This will be your new status message"
             style = "targetStatus"
         elif type_ == "ONE2ONE":
             style = "targetOne2One"
--- a/browser_side/radiocol.py	Wed Mar 05 21:42:03 2014 +0100
+++ b/browser_side/radiocol.py	Thu Mar 06 01:06:19 2014 +0100
@@ -36,6 +36,7 @@
 from html_tools import html_sanitize
 from file_tools import FilterFileUpload
 from sat_frontends.tools.misc import DEFAULT_MUC
+from sat.core.i18n import _
 
 
 class MetadataPanel(FlexTable):
@@ -86,7 +87,8 @@
 
         types = [('audio/ogg', '*.ogg', 'Ogg Vorbis Audio'),
                  ('video/ogg', '*.ogv', 'Ogg Vorbis Video'),
-                 ('application/ogg', '*.ogx', 'Ogg Vorbis Multiplex')]
+                 ('application/ogg', '*.ogx', 'Ogg Vorbis Multiplex'),
+                 ('audio/mpeg', '*.mp3', 'MPEG-Layer 3')]
         self.file_upload = FilterFileUpload("song", 10, types)
         vPanel.add(self.file_upload)
 
@@ -96,8 +98,11 @@
         self.status = Label()
         self.updateStatus()
         hPanel.add(self.status)
-        #We need to know the referee
+        #We need to know the filename and the referee
+        self.filename_field = Hidden('filename', '')
+        hPanel.add(self.filename_field)
         referee_field = Hidden('referee', self._parent.referee)
+        hPanel.add(self.filename_field)
         hPanel.add(referee_field)
         vPanel.add(hPanel)
 
@@ -122,9 +127,12 @@
 
     def onBtnClick(self):
         if self.file_upload.check():
+            self.status.setText('[Submitting, please wait...]')
+            self.filename_field.setValue(self.file_upload.getFilename())
+            if self.file_upload.getFilename().lower().endswith('.mp3'):
+                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)
             self.submit()
             self.file_upload.setFilename("")
-            self.status.setText('[Submitting, please wait...]')
 
     def onSubmit(self, event):
         pass
@@ -155,7 +163,7 @@
             self.setTemporaryStatus('[Your song has been submitted to the radio]', "ok")
         elif result == "KO":
             self.setTemporaryStatus('[Something went wrong during your song upload]', "ko")
-            self._parent.radiocolSongRejected("Uploaded file is not Ogg Vorbis song, only Ogg Vorbis songs are acceptable")
+            self._parent.radiocolSongRejected(_("The uploaded file has been rejected, only Ogg Vorbis and MP3 songs are accepted."))
             # TODO: would be great to re-use the original Exception class and message
             # but it is lost in the middle of the traceback and encapsulated within
             # a DBusException instance --> extract the data from the traceback?
@@ -232,9 +240,9 @@
             self.add(player)
         self.addClickListener(self)
 
-        help_msg = HTML("""- This radio plays Ogg Vorbis files.<br />
-        - What's that? I only know MP3!<br />
-        - Click <a style="color: red;">here</a> if you need some support :)
+        help_msg = HTML("""Accepted file formats: Ogg Vorbis (recommended), MP3.<br />
+        Please do not submit files that are protected by copyright.<br />
+        Click <a style="color: red;">here</a> if you need some support :)
         """)
         help_msg.setStyleName('chatTextInfo-link')
         help_msg.addClickListener(lambda: self._parent.host.bridge.call('joinMUC', None, DEFAULT_MUC, self._parent.nick))
--- a/libervia_server/__init__.py	Wed Mar 05 21:42:03 2014 +0100
+++ b/libervia_server/__init__.py	Thu Mar 06 01:06:19 2014 +0100
@@ -926,7 +926,8 @@
     NAME = 'song'
 
     def _getFileName(self, request):
-        return "%s.ogg" % str(uuid.uuid4()) #XXX: chromium doesn't seem to play song without the .ogg extension, even with audio/ogg mime-type
+        extension = os.path.splitext(request.args['filename'][0])[1]
+        return "%s%s" % (str(uuid.uuid4()), extension)  # XXX: chromium doesn't seem to play song without the .ogg extension, even with audio/ogg mime-type
 
     def _fileWritten(self, request, filepath):
         """Called once the file is actually written on disk