diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index f7116df15..377548ee8 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -82,6 +82,7 @@ class FtInTitlePlugin(plugins.BeetsPlugin): self.config.add({ 'auto': True, 'drop': False, + 'format': u'feat. {0}', }) self._command = ui.Subcommand( @@ -137,7 +138,9 @@ 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): - new_title = u"{0} feat. {1}".format(item.title, feat_part) + 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 diff --git a/docs/plugins/ftintitle.rst b/docs/plugins/ftintitle.rst index e2258942d..8a080b3e2 100644 --- a/docs/plugins/ftintitle.rst +++ b/docs/plugins/ftintitle.rst @@ -24,6 +24,9 @@ file. The available options are: - **drop**: Remove featured artists entirely instead of adding them to the title field. Default: ``no``. +- **format**: Defines the format for the featuring X part of the new title field. + In this format the ``{0}`` is used to define where the featured artists are placed. + Default: ``feat. {0}`` Running Manually ---------------- diff --git a/test/test_ftintitle.py b/test/test_ftintitle.py index 435230fb1..67b952a51 100644 --- a/test/test_ftintitle.py +++ b/test/test_ftintitle.py @@ -18,9 +18,61 @@ 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(self): + self._ft_set_config('feat. {0}') + 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') + + self._ft_set_config('featuring {0}') + 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') + + self._ft_set_config('with {0}') + 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"""