From 2b7538ee820bc5b6b60428db41abd6c5390d3813 Mon Sep 17 00:00:00 2001 From: SUTJael Date: Tue, 15 Apr 2014 23:04:41 +0200 Subject: [PATCH 1/4] Add drop option to FtInTitlePlugin --- beetsplug/ftintitle.py | 17 ++++++++++------- docs/plugins/ftintitle.rst | 3 +++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index 243c1f004..76c609557 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -48,7 +48,7 @@ def contains_feat(title): )) -def update_metadata(item, feat_part): +def update_metadata(item, feat_part, drop): """Choose how to add new artists to the title and set the new metadata. Also, print out messages about any changes that are made. """ @@ -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 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): """Look for featured artists in the item's artist fields and move them to the title. """ @@ -104,7 +104,7 @@ 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) else: ui.print_(u'no featuring artists found') @@ -115,13 +115,16 @@ class FtInTitlePlugin(BeetsPlugin): def commands(self): cmd = ui.Subcommand('ftintitle', help='move featured artists to the title field') - + cmd.parser.add_option('-d', '--drop', dest='drop_feat', + action='store_true', default=False, + help='drop featuring from artist (ignore title update)') def func(lib, opts, args): write = config['import']['write'].get(bool) for item in lib.items(ui.decargs(args)): - ft_in_title(item) + ft_in_title(item, opts.drop_feat) item.store() if write: item.try_write() + cmd.func = func return [cmd] diff --git a/docs/plugins/ftintitle.rst b/docs/plugins/ftintitle.rst index 19bb612c7..dc457a495 100644 --- a/docs/plugins/ftintitle.rst +++ b/docs/plugins/ftintitle.rst @@ -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 From 974e3128a6dc828f1aecb64a032cc8fe0dcad2e8 Mon Sep 17 00:00:00 2001 From: SUTJael Date: Mon, 21 Apr 2014 13:07:26 +0200 Subject: [PATCH 2/4] Fix formatting issues. Drop parameter sticky --- beetsplug/ftintitle.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index 76c609557..abae38367 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -48,7 +48,7 @@ def contains_feat(title): )) -def update_metadata(item, feat_part, drop): +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. """ @@ -61,13 +61,13 @@ def update_metadata(item, feat_part, drop): # Only update the title if it does not already contain a featured # artist and if we do not drop featuring information. - if not drop and not contains_feat(item.title): + 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, drop): +def ft_in_title(item, drop_feat): """Look for featured artists in the item's artist fields and move them to the title. """ @@ -104,7 +104,7 @@ def ft_in_title(item, drop): # If we have a featuring artist, move it to the title. if feat_part: - update_metadata(item, feat_part, drop) + update_metadata(item, feat_part, drop_feat) else: ui.print_(u'no featuring artists found') @@ -112,19 +112,34 @@ def ft_in_title(item, drop): 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') - cmd.parser.add_option('-d', '--drop', dest='drop_feat', - action='store_true', default=False, - help='drop featuring from artist (ignore title update)') + 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, opts.drop_feat) + 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] From 345d47b40df6cf2b003f99d2dfa40257abc45b28 Mon Sep 17 00:00:00 2001 From: SUTJael Date: Mon, 21 Apr 2014 16:06:34 +0200 Subject: [PATCH 3/4] Fix indent --- beetsplug/ftintitle.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index abae38367..e490a97bd 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -120,13 +120,12 @@ class FtInTitlePlugin(BeetsPlugin): }) self._command = ui.Subcommand('ftintitle', - help='move featured artists to' - ' the title field') + 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') + 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): From 4d616ceb93241763d2003d4ae066515bd6340e33 Mon Sep 17 00:00:00 2001 From: SUTJael Date: Mon, 21 Apr 2014 16:13:43 +0200 Subject: [PATCH 4/4] Fix styling --- beetsplug/ftintitle.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index e490a97bd..34cdbdcc6 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -119,7 +119,8 @@ class FtInTitlePlugin(BeetsPlugin): 'drop_feat': False }) - self._command = ui.Subcommand('ftintitle', + self._command = ui.Subcommand( + 'ftintitle', help='move featured artists to the title field') self._command.parser.add_option(