Improved handling for paths and added tests for it

This commit is contained in:
Rudi Grinberg 2012-10-12 15:54:38 -04:00
parent cefc5c99d9
commit ff8969efb9
4 changed files with 15 additions and 6 deletions

View File

@ -20,7 +20,8 @@ def load_definitions():
with md.metadata('MDATA_KEY_MIME') as t:
t.default(u'')
t.depends('mime')
t.translate(lambda k: k['mime'].replace('-','/'))
# Is this necessary?
t.translate(lambda k: k['mime'].replace('audio/vorbis','audio/ogg'))
with md.metadata('MDATA_KEY_BITRATE') as t:
t.default(u'')

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from contextlib import contextmanager
from media.monitor.pure import truncate_to_length, toposort
from os.path import normpath
from media.monitor.log import Loggable
import mutagen
@ -139,7 +140,7 @@ def normalize_mutagen(path):
md['bitrate'] = getattr(m.info, 'bitrate', u'')
md['sample_rate'] = getattr(m.info, 'sample_rate', 0)
md['mime'] = m.mime[0] if len(m.mime) > 0 else u''
md['path'] = path
md['path'] = normpath(path)
if 'title' not in md: md['title'] = u''
return md

View File

@ -312,7 +312,7 @@ def normalized_metadata(md, original_path):
# TODO : wtf is this for again?
new_md['MDATA_KEY_TITLE'] = re.sub(r'-?%s-?' % unicode_unknown, u'',
new_md['MDATA_KEY_TITLE'])
new_md['MDATA_KEY_ORIGINAL_PATH'] = original_path
new_md['MDATA_KEY_ORIGINAL_PATH'] = normpath(original_path)
return new_md
def organized_path(old_path, root_path, orig_md):

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import unittest
from pprint import pprint as pp
#from pprint import pprint as pp
from media.metadata.process import global_reader
from media.monitor.metadata import Metadata
@ -9,6 +9,13 @@ import media.metadata.definitions as defs
defs.load_definitions()
class TestMMP(unittest.TestCase):
def setUp(self):
self.maxDiff = None
def metadatas(self,f):
return global_reader.read_mutagen(f), Metadata(f).extract()
def test_old_metadata(self):
path = "/home/rudi/music/Nightingale.mp3"
m = global_reader.read_mutagen(path)
@ -18,8 +25,8 @@ class TestMMP(unittest.TestCase):
def test_recorded(self):
recorded_file = "./15:15:00-Untitled Show-256kbps.ogg"
m = global_reader.read_mutagen(recorded_file)
pp(m)
emf, old = self.metadatas(recorded_file)
self.assertEqual(emf, old)
if __name__ == '__main__': unittest.main()