mirror of
https://github.com/beetbox/beets.git
synced 2025-12-23 00:54:03 +01:00
Merge pull request #2974 from zsinskri/2973-lastgenre-prefer-specific-without-canonical
lastgenre prefer specific without canonical (#2973)
This commit is contained in:
commit
203ad7ff06
3 changed files with 33 additions and 4 deletions
|
|
@ -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.canonicalize:
|
||||
# Extend the list to consider tags parents in the c14n tree
|
||||
tags_all = []
|
||||
for tag in tags:
|
||||
|
|
|
|||
|
|
@ -23,9 +23,12 @@ Fixes:
|
|||
are missing.
|
||||
Thanks to :user:`autrimpo`.
|
||||
:bug:`2757`
|
||||
* Display the artist credit when matching albums if the ref:`artist_credit`
|
||||
* Display the artist credit when matching albums if the :ref:`artist_credit`
|
||||
configuration option is set.
|
||||
:bug:`2953`
|
||||
* LastGenre: Allow to set the configuration option ``prefer_specific``
|
||||
without setting ``canonical``.
|
||||
:bug:`2973`
|
||||
|
||||
|
||||
1.4.7 (May 29, 2018)
|
||||
|
|
|
|||
|
|
@ -36,9 +36,11 @@ class LastGenrePluginTest(unittest.TestCase, TestHelper):
|
|||
def tearDown(self):
|
||||
self.teardown_beets()
|
||||
|
||||
def _setup_config(self, whitelist=False, canonical=False, count=1):
|
||||
def _setup_config(self, whitelist=False, canonical=False, count=1,
|
||||
prefer_specific=False):
|
||||
config['lastgenre']['canonical'] = canonical
|
||||
config['lastgenre']['count'] = count
|
||||
config['lastgenre']['prefer_specific'] = prefer_specific
|
||||
if isinstance(whitelist, (bool, six.string_types)):
|
||||
# Filename, default, or disabled.
|
||||
config['lastgenre']['whitelist'] = whitelist
|
||||
|
|
@ -136,6 +138,21 @@ class LastGenrePluginTest(unittest.TestCase, TestHelper):
|
|||
self.assertEqual(self.plugin._resolve_genres(['iota blues']),
|
||||
u'')
|
||||
|
||||
def test_prefer_specific_loads_tree(self):
|
||||
"""When prefer_specific is enabled but canonical is not the
|
||||
tree still has to be loaded.
|
||||
"""
|
||||
self._setup_config(prefer_specific=True, canonical=False)
|
||||
self.assertNotEqual(self.plugin.c14n_branches, [])
|
||||
|
||||
def test_prefer_specific_without_canonical(self):
|
||||
"""Prefer_specific works without canonical.
|
||||
"""
|
||||
self._setup_config(prefer_specific=True, canonical=False, count=4)
|
||||
self.assertEqual(self.plugin._resolve_genres(
|
||||
['math rock', 'post-rock']),
|
||||
u'Post-Rock, Math Rock')
|
||||
|
||||
def test_no_duplicate(self):
|
||||
"""Remove duplicated genres.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue