diff --git a/python_apps/media-monitor2/media/monitor/airtime.py b/python_apps/media-monitor2/media/monitor/airtime.py index 23980929e..b920ecd65 100644 --- a/python_apps/media-monitor2/media/monitor/airtime.py +++ b/python_apps/media-monitor2/media/monitor/airtime.py @@ -2,13 +2,12 @@ from kombu.messaging import Exchange, Queue, Consumer from kombu.connection import BrokerConnection from os.path import normpath -from mutagen.easymp4 import EasyMP4KeyError import json import os import copy -from media.monitor.exceptions import BadSongFile +from media.monitor.exceptions import BadSongFile, InvalidMetadataElement from media.monitor.metadata import Metadata from media.monitor.log import Loggable from media.monitor.syncdb import AirtimeDB @@ -118,7 +117,7 @@ class AirtimeMessageReceiver(Loggable): try: Metadata.write_unsafe(path=md_path, md=msg) except BadSongFile as e: self.logger.info("Cannot find metadata file: '%s'" % e.path) - except EasyMP4KeyError as e: + except InvalidMetadataElement as e: self.logger.info("Metadata instance not supported for this file '%s'" \ % e.path) self.logger.info(str(e)) diff --git a/python_apps/media-monitor2/media/monitor/exceptions.py b/python_apps/media-monitor2/media/monitor/exceptions.py index c6b3ec445..b7b834920 100644 --- a/python_apps/media-monitor2/media/monitor/exceptions.py +++ b/python_apps/media-monitor2/media/monitor/exceptions.py @@ -48,3 +48,13 @@ class NoDirectoryInAirtime(Exception): def __str__(self): return "Directory '%s' does not exist in Airtime.\n \ However: %s do exist." % (self.path, self.does_exist) + +class InvalidMetadataElement(Exception): + def __init__(self, parent, key, path): + self.parent = parent + self.key = key + self.path = path + def __str__(self): + return "InvalidMetadataElement: (key,path) = (%s,%s)" \ + % (self.key, self.path) + diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index 8a56d51e1..5b62a204d 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -3,9 +3,9 @@ import mutagen import os import copy from collections import namedtuple -from mutagen.easymp4 import EasyMP4KeyError +from mutagen.easymp4 import EasyMP4KeyError, EasyID3KeyError -from media.monitor.exceptions import BadSongFile +from media.monitor.exceptions import BadSongFile, InvalidMetadataElement from media.monitor.log import Loggable from media.monitor.pure import format_length import media.monitor.pure as mmp @@ -150,17 +150,18 @@ class Metadata(Loggable): """ if not os.path.exists(path): raise BadSongFile(path) song_file = mutagen.File(path, easy=True) - ex = None + exceptions = [] # for bad keys for airtime_k, airtime_v in md.iteritems(): if airtime_k in airtime2mutagen: # The unicode cast here is mostly for integers that need to be # strings try: song_file[ airtime2mutagen[airtime_k] ] = unicode(airtime_v) - except EasyMP4KeyError as e: - ex = e + except (EasyMP4KeyError, EasyID3KeyError) as e: + exceptions.append(InvalidMetadataElement(e, airtime_k, + path)) + for e in exceptions: raise e song_file.save() - if ex: raise ex def __init__(self, fpath): # Forcing the unicode through