diff --git a/python_apps/media-monitor2/media/metadata/definitions.py b/python_apps/media-monitor2/media/metadata/definitions.py index 97b3f6841..a4f93848e 100644 --- a/python_apps/media-monitor2/media/metadata/definitions.py +++ b/python_apps/media-monitor2/media/metadata/definitions.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- import media.metadata.process as md +import re from os.path import normpath -from media.monitor.pure import format_length, file_md5 +from media.monitor.pure import format_length, file_md5, is_airtime_recorded, \ + no_extension_basename defs_loaded = False @@ -105,11 +107,32 @@ def load_definitions(): # MDATA_KEY_TITLE is the annoying special case b/c we sometimes read it # from file name + + + # must handle 3 cases: + # 1. regular case (not recorded + title is present) + # 2. title is absent (read from file) + # 3. recorded file + def tr_title(k): + unicode_unknown = u"unknown" + new_title = u"" + if is_airtime_recorded(k) or k['title'] != u"": + new_title = k['title'] + else: + default_title = no_extension_basename(k['path']) + default_title = re.sub(r'__\d+\.',u'.', default_title) + if re.match(".+-%s-.+$" % unicode_unknown, default_title): + default_title = u'' + new_title = default_title + new_title = re.sub(r'-\d+kbps$', u'', new_title) + return new_title + with md.metadata('MDATA_KEY_TITLE') as t: # Need to know MDATA_KEY_CREATOR to know if show was recorded. Value is # defaulted to "" from definitions above - t.depends('title','MDATA_KEY_CREATOR') - t.translate(lambda k: k['title']) + t.depends('title','MDATA_KEY_CREATOR','path') + t.optional(False) + t.translate(tr_title) t.max_length(512) with md.metadata('MDATA_KEY_LABEL') as t: diff --git a/python_apps/media-monitor2/media/metadata/process.py b/python_apps/media-monitor2/media/metadata/process.py index ca24feeb0..cde28cfaa 100644 --- a/python_apps/media-monitor2/media/metadata/process.py +++ b/python_apps/media-monitor2/media/metadata/process.py @@ -140,6 +140,7 @@ 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'] = path + if 'title' not in md: md['title'] = u'' return md diff --git a/python_apps/media-monitor2/tests/test_emf.py b/python_apps/media-monitor2/tests/test_emf.py index 545c059fd..3114e2f41 100644 --- a/python_apps/media-monitor2/tests/test_emf.py +++ b/python_apps/media-monitor2/tests/test_emf.py @@ -16,4 +16,10 @@ class TestMMP(unittest.TestCase): n = Metadata(path) self.assertEqual(n.extract(), m) + def test_recorded(self): + recorded_file = "./15:15:00-Untitled Show-256kbps.ogg" + m = global_reader.read_mutagen(recorded_file) + pp(m) + + if __name__ == '__main__': unittest.main()