Skip to content

Commit

Permalink
Merge pull request #1377 from amishb/custom_ft_title
Browse files Browse the repository at this point in the history
ftintitle plugin now allows a custom format to be defined (Correct Branch)
  • Loading branch information
sampsyo committed Mar 29, 2015
2 parents 13d65f9 + 9a38b07 commit eeca210
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion beetsplug/ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self):
self.config.add({
'auto': True,
'drop': False,
'format': u'feat. {0}',
})

self._command = ui.Subcommand(
Expand Down Expand Up @@ -137,7 +138,9 @@ def update_metadata(self, item, feat_part, drop_feat):
# 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

Expand Down
3 changes: 3 additions & 0 deletions docs/plugins/ftintitle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------
Expand Down
52 changes: 52 additions & 0 deletions test/test_ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,61 @@
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"""
Expand Down

0 comments on commit eeca210

Please sign in to comment.