plugin radiocol: add MP3 support
This commit is contained in:
parent
f00c02caed
commit
fcb9eeb570
1 changed files with 21 additions and 5 deletions
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 copy
|
|||
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 @@ class Radiocol(object):
|
|||
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],
|
||||
|
|
|
|||
Loading…
Reference in a new issue