Merge branch 'cc-3018-silence-detection' into devel

This commit is contained in:
James 2013-01-03 14:08:21 -05:00
commit a1837366be
16 changed files with 239 additions and 31 deletions

View file

@ -16,6 +16,16 @@ def load_definitions():
t.default(u'0.0')
t.depends('length')
t.translate(lambda k: format_length(k['length']))
with md.metadata('MDATA_KEY_CUE_IN') as t:
t.default(u'0.0')
t.depends('cuein')
t.translate(lambda k: format_length(k['cuein']))
with md.metadata('MDATA_KEY_CUE_OUT') as t:
t.default(u'0.0')
t.depends('cueout')
t.translate(lambda k: format_length(k['cueout']))
with md.metadata('MDATA_KEY_MIME') as t:
t.default(u'')

View file

@ -7,6 +7,8 @@ from media.monitor.log import Loggable
import media.monitor.pure as mmp
from collections import namedtuple
import mutagen
import subprocess
import json
class FakeMutagen(dict):
"""
@ -94,7 +96,6 @@ class MetadataElement(Loggable):
# If value is present and normalized then we only check if it's
# normalized or not. We normalize if it's not normalized already
if self.name in original:
v = original[self.name]
if self.__is_normalized(v): return v
@ -167,6 +168,18 @@ def normalize_mutagen(path):
md['sample_rate'] = getattr(m.info, 'sample_rate', 0)
md['mime'] = m.mime[0] if len(m.mime) > 0 else u''
md['path'] = normpath(path)
# silence detect(set default queue in and out)
try:
command = ['silan', '-f', 'JSON', md['path']]
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
out = proc.stdout.read()
info = json.loads(out)
md['cuein'] = info['sound'][0][0]
md['cueout'] = info['sound'][-1][1]
except Exception:
raise
if 'title' not in md: md['title'] = u''
return md

View file

@ -45,6 +45,8 @@ airtime2mutagen = {
"MDATA_KEY_URL" : "website",
"MDATA_KEY_ISRC" : "isrc",
"MDATA_KEY_COPYRIGHT" : "copyright",
"MDATA_KEY_CUE_IN" : "cuein",
"MDATA_KEY_CUE_OUT" : "cueout",
}

View file

@ -470,7 +470,7 @@ def format_length(mutagen_length):
m = int(math.floor(t / 60))
s = t % 60
# will be ss.uuu
s = str(s)
s = str('{0:f}'.format(s))
seconds = s.split(".")
s = seconds[0]
# have a maximum of 6 subseconds.