mirror of
https://github.com/beetbox/beets.git
synced 2026-01-30 12:02:41 +01:00
default arguments to %aunique{} (#190)
This commit is contained in:
parent
938a9b2f96
commit
8fe3738710
3 changed files with 16 additions and 4 deletions
|
|
@ -136,6 +136,7 @@ ITEM_DEFAULT_FIELDS = ARTIST_DEFAULT_FIELDS + ALBUM_DEFAULT_FIELDS + \
|
|||
# Special path format key.
|
||||
PF_KEY_DEFAULT = 'default'
|
||||
|
||||
|
||||
# Logger.
|
||||
log = logging.getLogger('beets')
|
||||
if not log.handlers:
|
||||
|
|
@ -895,9 +896,11 @@ class Library(BaseLibrary):
|
|||
for key, value in plugins.template_values(item).iteritems():
|
||||
mapping[key] = util.sanitize_for_path(value, pathmod, key)
|
||||
|
||||
# Perform substitution.
|
||||
# Get template functions.
|
||||
funcs = DefaultTemplateFunctions(self, item, pathmod).functions()
|
||||
funcs.update(plugins.template_funcs())
|
||||
|
||||
# Perform substitution.
|
||||
subpath = subpath_tmpl.substitute(mapping, funcs)
|
||||
|
||||
# Prepare path for output: normalize Unicode characters.
|
||||
|
|
@ -1426,7 +1429,7 @@ class DefaultTemplateFunctions(object):
|
|||
"""
|
||||
return unidecode(s)
|
||||
|
||||
def tmpl_unique(self, keys, disam):
|
||||
def tmpl_aunique(self, keys=None, disam=None):
|
||||
"""Generate a string that is guaranteed to be unique among all
|
||||
albums in the library who share the same set of keys. Fields
|
||||
from "disam" are used in the string if they are sufficient to
|
||||
|
|
@ -1434,6 +1437,8 @@ class DefaultTemplateFunctions(object):
|
|||
used. Both "keys" and "disam" should be given as
|
||||
whitespace-separated lists of field names.
|
||||
"""
|
||||
keys = keys or 'albumartist album'
|
||||
disam = disam or 'albumtype year label catalognum albumdisambig'
|
||||
keys = keys.split()
|
||||
disam = disam.split()
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -486,7 +486,7 @@ class DisambiguationTest(unittest.TestCase, PathFormattingMixin):
|
|||
self.lib.add_album([self.i2])
|
||||
self.lib.save()
|
||||
|
||||
self._setf(u'foo%unique{albumartist album,year}/$title')
|
||||
self._setf(u'foo%aunique{albumartist album,year}/$title')
|
||||
|
||||
def tearDown(self):
|
||||
self.lib.conn.close()
|
||||
|
|
@ -494,6 +494,13 @@ class DisambiguationTest(unittest.TestCase, PathFormattingMixin):
|
|||
def test_unique_expands_to_disambiguating_year(self):
|
||||
self._assert_dest('/base/foo [2001]/the title', self.i1)
|
||||
|
||||
def test_unique_with_default_arguments_uses_albumtype(self):
|
||||
album2 = self.lib.get_album(self.i1)
|
||||
album2.albumtype = 'bar'
|
||||
self.lib.save()
|
||||
self._setf(u'foo%aunique{}/$title')
|
||||
self._assert_dest('/base/foo [bar]/the title', self.i1)
|
||||
|
||||
def test_unique_expands_to_nothing_for_distinct_albums(self):
|
||||
album2 = self.lib.get_album(self.i2)
|
||||
album2.album = 'different album'
|
||||
|
|
@ -514,7 +521,7 @@ class DisambiguationTest(unittest.TestCase, PathFormattingMixin):
|
|||
album2.year = 2001
|
||||
album1 = self.lib.get_album(self.i1)
|
||||
album1.albumtype = 'foo/bar'
|
||||
self._setf(u'foo%unique{albumartist album,albumtype}/$title')
|
||||
self._setf(u'foo%aunique{albumartist album,albumtype}/$title')
|
||||
self._assert_dest('/base/foo [foo_bar]/the title', self.i1)
|
||||
|
||||
class PluginDestinationTest(unittest.TestCase):
|
||||
|
|
|
|||
Loading…
Reference in a new issue