Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drop option to FtInTitlePlugin #692

Merged
merged 4 commits into from Apr 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 28 additions & 10 deletions beetsplug/ftintitle.py
Expand Up @@ -48,7 +48,7 @@ def contains_feat(title):
))


def update_metadata(item, feat_part):
def update_metadata(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.
"""
Expand All @@ -60,14 +60,14 @@ def update_metadata(item, feat_part):
item.artist_sort, _ = split_on_feat(item.artist_sort)

# Only update the title if it does not already contain a featured
# artist.
if not contains_feat(item.title):
# 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)
ui.print_(u'title: {0} -> {1}'.format(item.title, new_title))
item.title = new_title


def ft_in_title(item):
def ft_in_title(item, drop_feat):
"""Look for featured artists in the item's artist fields and move
them to the title.
"""
Expand Down Expand Up @@ -104,24 +104,42 @@ def ft_in_title(item):

# If we have a featuring artist, move it to the title.
if feat_part:
update_metadata(item, feat_part)
update_metadata(item, feat_part, drop_feat)
else:
ui.print_(u'no featuring artists found')

ui.print_()


class FtInTitlePlugin(BeetsPlugin):
def __init__(self):
super(FtInTitlePlugin, self).__init__()

self.config.add({
'drop_feat': False
})

self._command = ui.Subcommand(
'ftintitle',
help='move featured artists to the title field')

self._command.parser.add_option(
'-d', '--drop', dest='drop_feat',
action='store_true', default=False,
help='drop featuring from artists and ignore title update')

def commands(self):
cmd = ui.Subcommand('ftintitle',
help='move featured artists to the title field')

def func(lib, opts, args):
self.config.set_args(opts)
drop_feat = self.config['drop_feat'].get(bool)
write = config['import']['write'].get(bool)

for item in lib.items(ui.decargs(args)):
ft_in_title(item)
ft_in_title(item, drop_feat)
item.store()
if write:
item.try_write()
cmd.func = func
return [cmd]

self._command.func = func
return [self._command]
3 changes: 3 additions & 0 deletions docs/plugins/ftintitle.rst
Expand Up @@ -17,4 +17,7 @@ To use the plugin, just enable it and run the command::
The query is optional; if it's left off, the transformation will be applied to
your entire collection.

The ``-d`` option drop only featuring information from the ``artist`` field. The
``title`` field will not be updated.

.. _MusicBrainz style: http://musicbrainz.org/doc/Style