# HG changeset patch # User souliane # Date 1394058243 -3600 # Node ID c238d2c02237260b606e0896a0c5e7ffa0a26726 # Parent 21681070f913284df0a1d5072e8450126e7db421 plugin radiocol: add MP3 support diff -r 21681070f913 -r c238d2c02237 src/plugins/plugin_misc_radiocol.py --- a/src/plugins/plugin_misc_radiocol.py Wed Mar 05 16:09:27 2014 +0100 +++ b/src/plugins/plugin_misc_radiocol.py Wed Mar 05 23:24:03 2014 +0100 @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from sat.core.i18n import _ +from sat.core.i18n import _, D_ from logging import debug, info, warning, error from twisted.words.xish import domish from twisted.internet import reactor @@ -29,6 +29,9 @@ import time from os import unlink from mutagen.oggvorbis import OggVorbis, OggVorbisHeaderError +from mutagen.mp3 import MP3, HeaderNotFoundError +from mutagen.easyid3 import EasyID3 +from mutagen.id3 import ID3NoHeaderError NC_RADIOCOL = 'http://www.goffi.org/protocol/radiocol' @@ -100,11 +103,24 @@ if not client: raise exceptions.NotConnectedProfileError(_("Can't access profile's data")) try: - song = OggVorbis(song_path) - except OggVorbisHeaderError: - #this file is not ogg vorbis, we reject it + if song_path.lower().endswith('.mp3'): + actual_song = MP3(song_path) + try: + song = EasyID3(song_path) + + class Info(object): + def __init__(self, length): + self.length = length + song.info = Info(actual_song.info.length) + except ID3NoHeaderError: + song = actual_song + else: + song = OggVorbis(song_path) + except (OggVorbisHeaderError, HeaderNotFoundError): + #this file is not ogg vorbis nor mp3, we reject it self.deleteFile(song_path) # FIXME: same host trick (see note above) - return defer.fail(exceptions.DataError("Uploaded file is not Ogg Vorbis song, only Ogg Vorbis songs are acceptable")) + return defer.fail(exceptions.DataError(D_("The uploaded file has been rejected, only Ogg Vorbis and MP3 songs are accepted."))) + attrs = {'filename': os.path.basename(song_path), 'title': song.get("title", ["Unknown"])[0], 'artist': song.get("artist", ["Unknown"])[0],