From 8fe3738710437c2a8d1016ffc2c10a12b448c357 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 24 Apr 2012 20:34:51 -0700 Subject: [PATCH] default arguments to %aunique{} (#190) --- beets/library.py | 9 +++++++-- test/rsrc/test.blb | Bin 7168 -> 7168 bytes test/test_db.py | 11 +++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) 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 4fe2abf95be6385ab40a8dbea686c10c724f8bbe..5181128bc92d54a2c79a037ba15ed8e507e187c9 100644 GIT binary patch delta 88 zcmZp$Xt0ienhluP#U&*f+pITd l2u)`c(oslGEJ@7CPtPmORVYcVDAC-^D8k0FnN8vsGXUlU6YBr~ delta 71 zcmZp$Xt0