fromfilename: Use logging magic from inherited BeetsPlugin
and change log level to INFO.
@@ -18,12 +18,9 @@ filename.
from beets import plugins
from beets.util import displayable_path
-from beets import logging
import os
import re
-log = logging.getLogger('beets')
-
# Filename field extraction patterns.
PATTERNS = [
# Useful patterns.
@@ -87,7 +84,7 @@ def bad_title(title):
return False
-def apply_matches(d):
+def apply_matches(d, log):
"""Given a mapping from items to field dicts, apply the fields to
the objects.
"""
@@ -115,9 +112,7 @@ def apply_matches(d):
for item in d:
if not item.artist:
item.artist = artist
- log.debug(
- 'fromfilename: Artist replaced with: {}'
- .format(item.artist))
+ log.info('Artist replaced with: {}'.format(item.artist))
# No artist field: remaining field is the title.
else:
@@ -127,14 +122,11 @@ def apply_matches(d):
for item in d:
if bad_title(item.title):
item.title = str(d[item][title_field])
- log.debug(
- 'fromfilename: Title replaced with: {}'
- .format(item.title))
+ log.info('Title replaced with: {}'.format(item.title))
+
if 'track' in d[item] and item.track == 0:
item.track = int(d[item]['track'])
- log.debug(
- 'fromfilename: Track replaced with: {}'
- .format(item.track))
+ log.info('Track replaced with: {}'.format(item.track))
# Plugin structure and hook into import process.
@@ -142,10 +134,9 @@ def apply_matches(d):
class FromFilenamePlugin(plugins.BeetsPlugin):
def __init__(self):
super().__init__()
- self.register_listener('import_task_start', filename_task)
-
+ self.register_listener('import_task_start', self.filename_task)
-def filename_task(task, session):
+ def filename_task(self, task, session):
"""Examine each item in the task to see if we can extract a title
from the filename. Try to match all filenames to a number of
regexps, starting with the most complex patterns and successively
@@ -170,4 +161,4 @@ def filename_task(task, session):
for pattern in PATTERNS:
d = all_matches(names, pattern)
if d:
- apply_matches(d)
+ apply_matches(d, self._log)
