diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index 0c3b7122c..83940a471 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -117,13 +117,12 @@ class FtInTitlePlugin(plugins.BeetsPlugin): """Import hook for moving featuring artist automatically. """ drop_feat = self.config['drop'].get(bool) - feat_format = self.config['format'].get(unicode) for item in task.imported_items(): - self.ft_in_title(item, drop_feat, feat_format) + self.ft_in_title(item, drop_feat) item.store() - def update_metadata(self, item, feat_part, drop_feat, feat_format): + def update_metadata(self, item, feat_part, drop_feat): """Choose how to add new artists to the title and set the new metadata. Also, print out messages about any changes that are made. If `drop_feat` is set, then do not add the artist to the title; just @@ -139,12 +138,13 @@ class FtInTitlePlugin(plugins.BeetsPlugin): # Only update the title if it does not already contain a featured # artist and if we do not drop featuring information. if not drop_feat and not contains_feat(item.title): + feat_format = self.config['format'].get(unicode) new_format = feat_format.format(feat_part) new_title = u"{0} {1}".format(item.title, new_format) self._log.info(u'title: {0} -> {1}', item.title, new_title) item.title = new_title - def ft_in_title(self, item, drop_feat, feat_format): + def ft_in_title(self, item, drop_feat): """Look for featured artists in the item's artist fields and move them to the title. """ @@ -165,6 +165,6 @@ class FtInTitlePlugin(plugins.BeetsPlugin): # If we have a featuring artist, move it to the title. if feat_part: - self.update_metadata(item, feat_part, drop_feat, feat_format) + self.update_metadata(item, feat_part, drop_feat) else: self._log.info(u'no featuring artists found') diff --git a/test/test_ftintitle.py b/test/test_ftintitle.py index 435230fb1..e849d3631 100644 --- a/test/test_ftintitle.py +++ b/test/test_ftintitle.py @@ -18,9 +18,65 @@ from __future__ import (division, absolute_import, print_function, unicode_literals) from test._common import unittest +from test.helper import TestHelper from beetsplug import ftintitle +class FtInTitlePluginFunctional(unittest.TestCase, TestHelper): + def setUp(self): + """Set up configuration""" + self.setup_beets() + self.load_plugins('ftintitle') + + def tearDown(self): + self.unload_plugins() + self.teardown_beets() + + def _ft_add_item(self,path, artist, title, aartist): + return self.add_item(path=path, + artist=artist, + title=title, + albumartist=aartist) + + def _ft_set_config(self, ftformat, drop = False, auto = True): + self.config['ftintitle']['format'] = ftformat + self.config['ftintitle']['drop'] = drop + self.config['ftintitle']['auto'] = auto + + def test_functional_drop(self): + item = self._ft_add_item('/', u'Alice ft Bob', u'Song 1', u'Alice') + self.run_command('ftintitle', '-d') + item.load() + self.assertEqual(item['artist'], u'Alice') + self.assertEqual(item['title'], u'Song 1') + + def test_functional_custom_format_1(self): + self._ft_set_config('feat. {}') + + item = self._ft_add_item('/', u'Alice ft Bob', u'Song 1', u'Alice') + self.run_command('ftintitle') + item.load() + self.assertEqual(item['artist'], u'Alice') + self.assertEqual(item['title'], u'Song 1 feat. Bob') + + def test_functional_custom_format_2(self): + self._ft_set_config('featuring {}') + + item = self._ft_add_item('/', u'Alice feat. Bob', u'Song 1', u'Alice') + self.run_command('ftintitle') + item.load() + self.assertEqual(item['artist'], u'Alice') + self.assertEqual(item['title'], u'Song 1 featuring Bob') + + def test_functional_custom_format_3(self): + self._ft_set_config('with {}') + + item = self._ft_add_item('/', u'Alice feat Bob', u'Song 1', u'Alice') + self.run_command('ftintitle') + item.load() + self.assertEqual(item['artist'], u'Alice') + self.assertEqual(item['title'], u'Song 1 with Bob') + class FtInTitlePluginTest(unittest.TestCase): def setUp(self): """Set up configuration"""