cc-4493: Cleaned up handling of metadata specific to filetypes.
This commit is contained in:
parent
d55915d649
commit
a20dc7dc96
|
@ -2,13 +2,12 @@
|
||||||
from kombu.messaging import Exchange, Queue, Consumer
|
from kombu.messaging import Exchange, Queue, Consumer
|
||||||
from kombu.connection import BrokerConnection
|
from kombu.connection import BrokerConnection
|
||||||
from os.path import normpath
|
from os.path import normpath
|
||||||
from mutagen.easymp4 import EasyMP4KeyError
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from media.monitor.exceptions import BadSongFile
|
from media.monitor.exceptions import BadSongFile, InvalidMetadataElement
|
||||||
from media.monitor.metadata import Metadata
|
from media.monitor.metadata import Metadata
|
||||||
from media.monitor.log import Loggable
|
from media.monitor.log import Loggable
|
||||||
from media.monitor.syncdb import AirtimeDB
|
from media.monitor.syncdb import AirtimeDB
|
||||||
|
@ -118,7 +117,7 @@ class AirtimeMessageReceiver(Loggable):
|
||||||
try: Metadata.write_unsafe(path=md_path, md=msg)
|
try: Metadata.write_unsafe(path=md_path, md=msg)
|
||||||
except BadSongFile as e:
|
except BadSongFile as e:
|
||||||
self.logger.info("Cannot find metadata file: '%s'" % e.path)
|
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'" \
|
self.logger.info("Metadata instance not supported for this file '%s'" \
|
||||||
% e.path)
|
% e.path)
|
||||||
self.logger.info(str(e))
|
self.logger.info(str(e))
|
||||||
|
|
|
@ -48,3 +48,13 @@ class NoDirectoryInAirtime(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Directory '%s' does not exist in Airtime.\n \
|
return "Directory '%s' does not exist in Airtime.\n \
|
||||||
However: %s do exist." % (self.path, self.does_exist)
|
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)
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ import mutagen
|
||||||
import os
|
import os
|
||||||
import copy
|
import copy
|
||||||
from collections import namedtuple
|
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.log import Loggable
|
||||||
from media.monitor.pure import format_length
|
from media.monitor.pure import format_length
|
||||||
import media.monitor.pure as mmp
|
import media.monitor.pure as mmp
|
||||||
|
@ -150,17 +150,18 @@ class Metadata(Loggable):
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(path): raise BadSongFile(path)
|
if not os.path.exists(path): raise BadSongFile(path)
|
||||||
song_file = mutagen.File(path, easy=True)
|
song_file = mutagen.File(path, easy=True)
|
||||||
ex = None
|
exceptions = [] # for bad keys
|
||||||
for airtime_k, airtime_v in md.iteritems():
|
for airtime_k, airtime_v in md.iteritems():
|
||||||
if airtime_k in airtime2mutagen:
|
if airtime_k in airtime2mutagen:
|
||||||
# The unicode cast here is mostly for integers that need to be
|
# The unicode cast here is mostly for integers that need to be
|
||||||
# strings
|
# strings
|
||||||
try:
|
try:
|
||||||
song_file[ airtime2mutagen[airtime_k] ] = unicode(airtime_v)
|
song_file[ airtime2mutagen[airtime_k] ] = unicode(airtime_v)
|
||||||
except EasyMP4KeyError as e:
|
except (EasyMP4KeyError, EasyID3KeyError) as e:
|
||||||
ex = e
|
exceptions.append(InvalidMetadataElement(e, airtime_k,
|
||||||
|
path))
|
||||||
|
for e in exceptions: raise e
|
||||||
song_file.save()
|
song_file.save()
|
||||||
if ex: raise ex
|
|
||||||
|
|
||||||
def __init__(self, fpath):
|
def __init__(self, fpath):
|
||||||
# Forcing the unicode through
|
# Forcing the unicode through
|
||||||
|
|
Loading…
Reference in New Issue