mirror of
https://github.com/beetbox/beets.git
synced 2025-12-29 20:12:33 +01:00
Make 2 plugins rely on auto log level mgmt
ftintitle and title don't do manual management anymore.
This commit is contained in:
parent
427f7e7035
commit
1afe82fb41
2 changed files with 17 additions and 23 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue