Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
b69f3288d3
13 changed files with 56 additions and 32 deletions
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
import mutagen
|
||||
import os
|
||||
import copy
|
||||
from collections import namedtuple
|
||||
from mutagen.easymp4 import EasyMP4KeyError
|
||||
from collections import namedtuple
|
||||
from mutagen.easymp4 import EasyMP4KeyError
|
||||
from mutagen.easyid3 import 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 +151,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
|
||||
|
|
|
@ -257,6 +257,8 @@ def normalized_metadata(md, original_path):
|
|||
'MDATA_KEY_FILEPATH' : lambda x: os.path.normpath(x),
|
||||
'MDATA_KEY_BPM' : lambda x: x[0:8],
|
||||
'MDATA_KEY_MIME' : lambda x: x.replace('audio/vorbis','audio/ogg'),
|
||||
# Whenever 0 is reported we change it to empty
|
||||
#'MDATA_KEY_BITRATE' : lambda x: '' if str(x) == '0' else x
|
||||
}
|
||||
|
||||
new_md = remove_whitespace(new_md) # remove whitespace fields
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue