mirror of
https://github.com/beetbox/beets.git
synced 2025-12-23 09:03:49 +01:00
Merge pull request #1377 from amishb/custom_ft_title
ftintitle plugin now allows a custom format to be defined (Correct Branch)
This commit is contained in:
commit
eeca2105f9
3 changed files with 59 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
----------------
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue