From cef9a3311c6ba169bcd1f63dacb9dcf58e1e0ddf Mon Sep 17 00:00:00 2001 From: Zsin Skri Date: Sat, 30 Jun 2018 22:27:29 +0200 Subject: [PATCH] LastGenre: allow prefer_specific without canonical This improves lastgenre's behaviour when the configuration option `prefer_specific` is set but `canonical` is not. Previously it would not set any tags. Now it does apply tags, sorted using the canonicalization tree, but not canonicalized. For this the default tree is loaded even when `canonical` is not set. An extra check is added to only use it for canonicalization when `canonical` is set. --- beetsplug/lastgenre/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 4374310ba..6c195f6c4 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -138,9 +138,18 @@ class LastGenrePlugin(plugins.BeetsPlugin): # Read the genres tree for canonicalization if enabled. self.c14n_branches = [] c14n_filename = self.config['canonical'].get() - if c14n_filename in (True, ''): # Default tree. + self.canonicalize = c14n_filename is not False + + # Default tree + if c14n_filename in (True, ''): c14n_filename = C14N_TREE + elif not self.canonicalize and self.config['prefer_specific'].get(): + # prefer_specific requires a tree, load default tree + c14n_filename = C14N_TREE + + # Read the tree if c14n_filename: + self._log.debug('Loading canonicalization tree {0}', c14n_filename) c14n_filename = normpath(c14n_filename) with codecs.open(c14n_filename, 'r', encoding='utf-8') as f: genres_tree = yaml.load(f) @@ -186,7 +195,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): return None count = self.config['count'].get(int) - if self.c14n_branches: + if self.c14n_branches and self.canonicalize: # Extend the list to consider tags parents in the c14n tree tags_all = [] for tag in tags: