diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index dcf5b2fe2..fb68fb247 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -38,7 +38,6 @@ from beets import library log = logging.getLogger('beets') LASTFM = pylast.LastFMNetwork(api_key=plugins.LASTFM_KEY) -C14N_TREE = os.path.join(os.path.dirname(__file__), 'genres-tree.yaml') PYLAST_EXCEPTIONS = ( pylast.WSError, @@ -113,12 +112,16 @@ def find_parents(candidate, branches): # Main plugin logic. +WHITELIST = os.path.join(os.path.dirname(__file__), 'genres.txt') +C14N_TREE = os.path.join(os.path.dirname(__file__), 'genres-tree.yaml') + + class LastGenrePlugin(plugins.BeetsPlugin): def __init__(self): super(LastGenrePlugin, self).__init__() self.config.add({ - 'whitelist': os.path.join(os.path.dirname(__file__), 'genres.txt'), + 'whitelist': None, 'min_weight': 10, 'count': 1, 'fallback': None, @@ -139,13 +142,20 @@ class LastGenrePlugin(plugins.BeetsPlugin): self._genre_cache = {} - # Read the whitelist file. + # Read the whitelist file if enabled. self.whitelist = set() - with open(self.config['whitelist'].as_filename()) as f: - for line in f: - line = line.decode('utf8').strip().lower() - if line and not line.startswith(u'#'): - self.whitelist.add(line) + wl_filename = self.config['whitelist'].get() + if wl_filename is not None: + wl_filename = wl_filename.strip() + if not wl_filename: + wl_filename = WHITELIST + wl_filename = normpath(wl_filename) + with open(wl_filename, 'r') as f: + # with open(self.config['whitelist'].as_filename()) as f: + for line in f: + line = line.decode('utf8').strip().lower() + if line and not line.startswith(u'#'): + self.whitelist.add(line) # Read the genres tree for canonicalization if enabled. self.c14n_branches = []