diff --git a/beets/library.py b/beets/library.py index 0d464cb5e..cfc9e2727 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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() diff --git a/test/rsrc/test.blb b/test/rsrc/test.blb index 4fe2abf95..5181128bc 100644 Binary files a/test/rsrc/test.blb and b/test/rsrc/test.blb differ diff --git a/test/test_db.py b/test/test_db.py index ce61c6a04..6140998a3 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -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):