cc-4241: Partially resolved issue. Added tests.

This commit is contained in:
Rudi Grinberg 2012-08-29 18:08:14 -04:00
parent b75f2ab9c7
commit ef7c30b55e
4 changed files with 37 additions and 1 deletions

View file

@ -105,6 +105,16 @@ class Metadata(Loggable):
# little bit messy. Some of the handling is in m.m.pure while the rest is
# 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
def airtime_dict(d):
"""

View file

@ -6,6 +6,7 @@ from media.monitor.handler import ReportHandler
from media.monitor.log import Loggable
from media.monitor.exceptions import BadSongFile
from media.monitor.events import OrganizeFile
from media.monitor.metadata import Metadata
from pydispatch import dispatcher
from os.path import dirname
@ -65,8 +66,11 @@ class Organizer(ReportHandler,Loggable):
directory=d)
return cb
Metadata.fix_title(event.path)
mmp.magic_move(event.path, new_path,
after_dir_make=new_dir_watch(dirname(new_path)))
owners.add_file_owner(new_path, mmp.owner_id(event.path) )
self.logger.info('Organized: "%s" into "%s"' %
(event.path, new_path))

View file

@ -252,15 +252,21 @@ def normalized_metadata(md, original_path):
if new_md['MDATA_KEY_BPM'] is None:
del new_md['MDATA_KEY_BPM']
if is_airtime_recorded(new_md):
hour,minute,second,name = new_md['MDATA_KEY_TITLE'].split("-",3)
new_md['MDATA_KEY_TITLE'] = u'%s-%s-%s:%s:%s' % \
(name, new_md['MDATA_KEY_YEAR'], hour, minute, second)
else:
# 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'],
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
def organized_path(old_path, root_path, orig_md):