diff 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
line wrap: on
line diff
--- 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))