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

ftintitle: use log.log() for outputting #1176

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions beetsplug/ftintitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ def contains_feat(title):
return bool(re.search(plugins.feat_tokens(), title, flags=re.IGNORECASE))


def update_metadata(item, feat_part, drop_feat):
def update_metadata(item, feat_part, drop_feat, loglevel=logging.DEBUG):
"""Choose how to add new artists to the title and set the new
metadata. Also, print out messages about any changes that are made.
If `drop_feat` is set, then do not add the artist to the title; just
remove it from the artist field.
"""
# In all cases, update the artist fields.
ui.print_(u'artist: {0} -> {1}'.format(item.artist, item.albumartist))
log.log(loglevel, u'artist: {0} -> {1}'.format(
item.artist, item.albumartist))
item.artist = item.albumartist
if item.artist_sort:
# Just strip the featured artist from the sort name.
Expand All @@ -62,11 +63,11 @@ def update_metadata(item, feat_part, drop_feat):
# 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))
log.log(loglevel, u'title: {0} -> {1}'.format(item.title, new_title))
item.title = new_title


def ft_in_title(item, drop_feat):
def ft_in_title(item, drop_feat, loglevel=logging.DEBUG):
"""Look for featured artists in the item's artist fields and move
them to the title.
"""
Expand All @@ -78,14 +79,14 @@ def ft_in_title(item, drop_feat):
# that case, we attempt to move the featured artist to the title.
_, featured = split_on_feat(artist)
if featured and albumartist != artist and albumartist:
ui.print_(displayable_path(item.path))
log.log(loglevel, displayable_path(item.path))
feat_part = None

# Look for the album artist in the artist field. If it's not
# present, give up.
albumartist_split = artist.split(albumartist)
if len(albumartist_split) <= 1:
ui.print_('album artist not present in artist')
log.log(loglevel, 'album artist not present in artist')

# If the last element of the split (the right-hand side of the
# album artist) is nonempty, then it probably contains the
Expand All @@ -103,11 +104,9 @@ def ft_in_title(item, drop_feat):

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

ui.print_()
log.log(loglevel, u'no featuring artists found')


class FtInTitlePlugin(plugins.BeetsPlugin):
Expand Down Expand Up @@ -139,7 +138,7 @@ def func(lib, opts, args):
write = config['import']['write'].get(bool)

for item in lib.items(ui.decargs(args)):
ft_in_title(item, drop_feat)
ft_in_title(item, drop_feat, logging.INFO)
item.store()
if write:
item.try_write()
Expand All @@ -153,5 +152,5 @@ def imported(self, session, task):
drop_feat = self.config['drop'].get(bool)

for item in task.imported_items():
ft_in_title(item, drop_feat)
ft_in_title(item, drop_feat, logging.DEBUG)
item.store()