cc-4241: Partially resolved issue. Added tests.
This commit is contained in:
parent
b75f2ab9c7
commit
ef7c30b55e
|
@ -105,6 +105,16 @@ class Metadata(Loggable):
|
||||||
# little bit messy. Some of the handling is in m.m.pure while the rest is
|
# little bit messy. Some of the handling is in m.m.pure while the rest is
|
||||||
# here. Also interface is not very consistent
|
# here. Also interface is not very consistent
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def fix_title(self, path):
|
||||||
|
# If we have no title in path we will format it
|
||||||
|
# TODO : this is very hacky so make sure to fix it
|
||||||
|
m = mutagen.File(path, easy=True)
|
||||||
|
if u'title' not in m:
|
||||||
|
new_title = unicode( mmp.no_extension_basename(path) )
|
||||||
|
m[u'title'] = new_title
|
||||||
|
m.save()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def airtime_dict(d):
|
def airtime_dict(d):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -6,6 +6,7 @@ from media.monitor.handler import ReportHandler
|
||||||
from media.monitor.log import Loggable
|
from media.monitor.log import Loggable
|
||||||
from media.monitor.exceptions import BadSongFile
|
from media.monitor.exceptions import BadSongFile
|
||||||
from media.monitor.events import OrganizeFile
|
from media.monitor.events import OrganizeFile
|
||||||
|
from media.monitor.metadata import Metadata
|
||||||
from pydispatch import dispatcher
|
from pydispatch import dispatcher
|
||||||
from os.path import dirname
|
from os.path import dirname
|
||||||
|
|
||||||
|
@ -65,8 +66,11 @@ class Organizer(ReportHandler,Loggable):
|
||||||
directory=d)
|
directory=d)
|
||||||
return cb
|
return cb
|
||||||
|
|
||||||
|
Metadata.fix_title(event.path)
|
||||||
|
|
||||||
mmp.magic_move(event.path, new_path,
|
mmp.magic_move(event.path, new_path,
|
||||||
after_dir_make=new_dir_watch(dirname(new_path)))
|
after_dir_make=new_dir_watch(dirname(new_path)))
|
||||||
|
|
||||||
owners.add_file_owner(new_path, mmp.owner_id(event.path) )
|
owners.add_file_owner(new_path, mmp.owner_id(event.path) )
|
||||||
self.logger.info('Organized: "%s" into "%s"' %
|
self.logger.info('Organized: "%s" into "%s"' %
|
||||||
(event.path, new_path))
|
(event.path, new_path))
|
||||||
|
|
|
@ -252,15 +252,21 @@ def normalized_metadata(md, original_path):
|
||||||
if new_md['MDATA_KEY_BPM'] is None:
|
if new_md['MDATA_KEY_BPM'] is None:
|
||||||
del new_md['MDATA_KEY_BPM']
|
del new_md['MDATA_KEY_BPM']
|
||||||
|
|
||||||
|
|
||||||
if is_airtime_recorded(new_md):
|
if is_airtime_recorded(new_md):
|
||||||
hour,minute,second,name = new_md['MDATA_KEY_TITLE'].split("-",3)
|
hour,minute,second,name = new_md['MDATA_KEY_TITLE'].split("-",3)
|
||||||
new_md['MDATA_KEY_TITLE'] = u'%s-%s-%s:%s:%s' % \
|
new_md['MDATA_KEY_TITLE'] = u'%s-%s-%s:%s:%s' % \
|
||||||
(name, new_md['MDATA_KEY_YEAR'], hour, minute, second)
|
(name, new_md['MDATA_KEY_YEAR'], hour, minute, second)
|
||||||
else:
|
else:
|
||||||
# Read title from filename if it does not exist
|
# Read title from filename if it does not exist
|
||||||
|
default_title = no_extension_basename(original_path)
|
||||||
|
if re.match(".+-%s-.+$" % unicode_unknown, default_title):
|
||||||
|
default_title = u''
|
||||||
new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'],
|
new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'],
|
||||||
default=no_extension_basename(original_path))
|
default=default_title)
|
||||||
|
|
||||||
|
new_md['MDATA_KEY_TITLE'] = re.sub(r'-?%s-?' % unicode_unknown, u'',
|
||||||
|
new_md['MDATA_KEY_TITLE'])
|
||||||
return new_md
|
return new_md
|
||||||
|
|
||||||
def organized_path(old_path, root_path, orig_md):
|
def organized_path(old_path, root_path, orig_md):
|
||||||
|
|
|
@ -80,6 +80,22 @@ class TestMMP(unittest.TestCase):
|
||||||
# TODO : add a better test than this...
|
# TODO : add a better test than this...
|
||||||
self.assertTrue( len(opath) > 0 )
|
self.assertTrue( len(opath) > 0 )
|
||||||
|
|
||||||
|
def test_normalized_metadata3(self):
|
||||||
|
"""
|
||||||
|
Test the case where the metadata is empty
|
||||||
|
"""
|
||||||
|
orig = Metadata.airtime_dict({})
|
||||||
|
paths_unknown_title = [
|
||||||
|
("/testin/unknown-unknown-unknown.mp3",""),
|
||||||
|
("/testin/01-unknown-123kbps.mp3",""),
|
||||||
|
("/testin/02-unknown-140kbps.mp3",""),
|
||||||
|
("/testin/unknown-unknown-123kbps.mp3",""),
|
||||||
|
("/testin/unknown-bibimbop-unknown.mp3","bibimbop"),
|
||||||
|
]
|
||||||
|
for p,res in paths_unknown_title:
|
||||||
|
normalized = mmp.normalized_metadata(orig, p)
|
||||||
|
self.assertEqual( normalized['MDATA_KEY_TITLE'], res)
|
||||||
|
|
||||||
def test_file_md5(self):
|
def test_file_md5(self):
|
||||||
p = os.path.realpath(__file__)
|
p = os.path.realpath(__file__)
|
||||||
m1 = mmp.file_md5(p)
|
m1 = mmp.file_md5(p)
|
||||||
|
|
Loading…
Reference in New Issue