summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2013-11-24 22:01:32 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2013-11-24 22:01:32 +0200
commitd4ae7ee22933c2fc2679e688c3caeb11409f5ba2 (patch)
tree35eae18202cd3357f825db781373661db7d3297f
parentd9181d20ec01d4c102eeffeb3eaab63b865036f0 (diff)
Support Opus metadata, small compatibility fix.
-rwxr-xr-xvalosoitin/Valosoitin.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/valosoitin/Valosoitin.py b/valosoitin/Valosoitin.py
index c516bc4..9898329 100755
--- a/valosoitin/Valosoitin.py
+++ b/valosoitin/Valosoitin.py
@@ -29,12 +29,17 @@ import datetime
29import cgi 29import cgi
30import ConfigParser 30import ConfigParser
31import cPickle 31import cPickle
32
32import random 33import random
33random.seed() 34random.seed()
35
34import mimetypes 36import mimetypes
35mimetypes.init() 37mimetypes.init()
38mimetypes.add_type("audio/opus", ".opus", strict=True)
39
36import logging 40import logging
37logging.basicConfig(level=logging.DEBUG) 41logging.basicConfig(level=logging.DEBUG)
42
38import gettext 43import gettext
39gettext.install("valosoitin", unicode=True) 44gettext.install("valosoitin", unicode=True)
40 45
@@ -183,7 +188,10 @@ class Valosoitin(object):
183 playtimer.freeze() 188 playtimer.freeze()
184 189
185 # Setup Emotion 190 # Setup Emotion
186 self.player = player = Emotion(window.evas_get(), module_filename=conf.get("Settings", "audio_backend")) 191 try:
192 self.player = player = Emotion(window.evas_get(), module_name=conf.get("Settings", "audio_backend"))
193 except TypeError:
194 self.player = player = Emotion(window.evas_get(), module_filename=conf.get("Settings", "audio_backend"))
187 player.video_mute_set(True) 195 player.video_mute_set(True)
188 player.callback_add("playback_started", self.playing) 196 player.callback_add("playback_started", self.playing)
189 player.callback_add("playback_finished", self.finished) 197 player.callback_add("playback_finished", self.finished)
@@ -329,6 +337,8 @@ class Valosoitin(object):
329 logging.info("Invalid type %s for file %s" % (mimetype, f)) 337 logging.info("Invalid type %s for file %s" % (mimetype, f))
330 return False 338 return False
331 339
340 m = None
341
332 if mimetype == "audio/mpeg": 342 if mimetype == "audio/mpeg":
333 try: 343 try:
334 m = EasyID3(f) 344 m = EasyID3(f)
@@ -336,15 +346,31 @@ class Valosoitin(object):
336 try: 346 try:
337 m = mutagen.mp3.MP3(f) 347 m = mutagen.mp3.MP3(f)
338 except mutagen.mp3.HeaderNotFoundError: 348 except mutagen.mp3.HeaderNotFoundError:
339 logging.info("Mpeg audio header not found, trying with generic type") 349 logging.info("Mpeg audio header not found.")
340 m = mutagen.File(f, easy=True)
341 elif mimetype == "audio/flac": 350 elif mimetype == "audio/flac":
342 m = mutagen.flac.FLAC(f) 351 try:
352 m = mutagen.flac.FLAC(f)
353 except mutagen.flac.FLACNoHeaderError, mutagen.flac.FLACVorbisError:
354 logging.info("Invalid header in FLAC file.")
355 elif mimetype == "audio/opus":
356 try:
357 m = mutagen.oggopus.OggOpus(f)
358 except mutagen.oggopus.OggOpusHeaderError:
359 logging.info("Invalid header in Opus file.")
343 elif mimetype == "audio/ogg": 360 elif mimetype == "audio/ogg":
344 m = mutagen.oggvorbis.OggVorbis(f) 361 try:
362 m = mutagen.oggvorbis.OggVorbis(f)
363 except mutagen.oggvorbis.OggVorbisHeaderError:
364 logging.info("Invalid header in Ogg Vorbis file.")
345 else: 365 else:
346 logging.info("No known mutagen type for %s" % mimetype) 366 logging.info("No known mutagen type for %s." % mimetype)
347 m = mutagen.File(f, easy=True) 367
368 if m is None:
369 logging.info("Trying generic type for %s" % f)
370 try:
371 m = mutagen.File(f, easy=True)
372 except Exception:
373 pass
348 374
349 if m is None: 375 if m is None:
350 return False 376 return False