From 1afe82fb41c82cff0876c35609d4fca7906063cd Mon Sep 17 00:00:00 2001 From: Bruno Cauet Date: Mon, 5 Jan 2015 12:40:21 +0100 Subject: [PATCH] Make 2 plugins rely on auto log level mgmt ftintitle and title don't do manual management anymore. --- beetsplug/ftintitle.py | 20 ++++++++++---------- beetsplug/lyrics.py | 20 +++++++------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/beetsplug/ftintitle.py b/beetsplug/ftintitle.py index b72113e4c..22504a1fe 100644 --- a/beetsplug/ftintitle.py +++ b/beetsplug/ftintitle.py @@ -46,14 +46,14 @@ def contains_feat(title): return bool(re.search(plugins.feat_tokens(), title, flags=re.IGNORECASE)) -def update_metadata(item, feat_part, drop_feat, loglevel=logging.DEBUG): +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. 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. - log.log(loglevel, u'artist: {0} -> {1}', item.artist, item.albumartist) + log.info(u'artist: {0} -> {1}', item.artist, item.albumartist) item.artist = item.albumartist if item.artist_sort: # Just strip the featured artist from the sort name. @@ -63,11 +63,11 @@ def update_metadata(item, feat_part, drop_feat, loglevel=logging.DEBUG): # 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) - log.log(loglevel, u'title: {0} -> {1}', item.title, new_title) + log.info(u'title: {0} -> {1}', item.title, new_title) item.title = new_title -def ft_in_title(item, drop_feat, loglevel=logging.DEBUG): +def ft_in_title(item, drop_feat): """Look for featured artists in the item's artist fields and move them to the title. """ @@ -79,14 +79,14 @@ def ft_in_title(item, drop_feat, loglevel=logging.DEBUG): # that case, we attempt to move the featured artist to the title. _, featured = split_on_feat(artist) if featured and albumartist != artist and albumartist: - log.log(loglevel, displayable_path(item.path)) + log.info(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, 1) if len(albumartist_split) <= 1: - log.log(loglevel, 'album artist not present in artist') + log.info('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 @@ -104,9 +104,9 @@ def ft_in_title(item, drop_feat, loglevel=logging.DEBUG): # If we have a featuring artist, move it to the title. if feat_part: - update_metadata(item, feat_part, drop_feat, loglevel) + update_metadata(item, feat_part, drop_feat) else: - log.log(loglevel, u'no featuring artists found') + log.info(u'no featuring artists found') class FtInTitlePlugin(plugins.BeetsPlugin): @@ -138,7 +138,7 @@ class FtInTitlePlugin(plugins.BeetsPlugin): write = config['import']['write'].get(bool) for item in lib.items(ui.decargs(args)): - ft_in_title(item, drop_feat, logging.INFO) + ft_in_title(item, drop_feat) item.store() if write: item.try_write() @@ -152,5 +152,5 @@ class FtInTitlePlugin(plugins.BeetsPlugin): drop_feat = self.config['drop'].get(bool) for item in task.imported_items(): - ft_in_title(item, drop_feat, logging.DEBUG) + ft_in_title(item, drop_feat) item.store() diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 3c413c49e..710cdd2e4 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -477,7 +477,7 @@ class LyricsPlugin(plugins.BeetsPlugin): write = config['import']['write'].get(bool) for item in lib.items(ui.decargs(args)): self.fetch_item_lyrics( - lib, logging.INFO, item, write, + lib, item, write, opts.force_refetch or self.config['force'], ) if opts.printlyr and item.lyrics: @@ -491,19 +491,15 @@ class LyricsPlugin(plugins.BeetsPlugin): """ if self.config['auto']: for item in task.imported_items(): - self.fetch_item_lyrics(session.lib, logging.DEBUG, item, + self.fetch_item_lyrics(session.lib, item, False, self.config['force']) - def fetch_item_lyrics(self, lib, loglevel, item, write, force): + def fetch_item_lyrics(self, lib, item, write, force): """Fetch and store lyrics for a single item. If ``write``, then the - lyrics will also be written to the file itself. The ``loglevel`` - parameter controls the visibility of the function's status log - messages. - """ + lyrics will also be written to the file itself.""" # Skip if the item already has lyrics. if not force and item.lyrics: - log.log(loglevel, u'lyrics already present: {0} - {1}', - item.artist, item.title) + log.info(u'lyrics already present: {0.artist} - {0.title}', item) return lyrics = None @@ -515,11 +511,9 @@ class LyricsPlugin(plugins.BeetsPlugin): lyrics = u"\n\n---\n\n".join([l for l in lyrics if l]) if lyrics: - log.log(loglevel, u'fetched lyrics: {0} - {1}', - item.artist, item.title) + log.info(u'fetched lyrics: {0} - {1}', item.artist, item.title) else: - log.log(loglevel, u'lyrics not found: {0} - {1}', - item.artist, item.title) + log.info(u'lyrics not found: {0} - {1}', item.artist, item.title) fallback = self.config['fallback'].get() if fallback: lyrics = fallback