I’m wondering if it’s possible to use template functions like %aunique
from inline python (inline
plugin) in a path format. Thanks!
-kergoth
Not directly, unfortunately! But you might be able to invoke the underlying Python functions:
"""
return util.asciify_path(s, beets.config['path_sep_replace'].as_str())
@staticmethod
def tmpl_time(s, fmt):
"""Format a time value using `strftime`.
"""
cur_fmt = beets.config['time_format'].as_str()
return time.strftime(fmt, time.strptime(s, cur_fmt))
def tmpl_aunique(self, keys=None, disam=None, bracket=None):
"""Generate a string that is guaranteed to be unique among all
albums in the library who share the same set of keys. A fields
from "disam" is used in the string if one is sufficient to
disambiguate the albums. Otherwise, a fallback opaque value is
used. Both "keys" and "disam" should be given as
whitespace-separated lists of field names, while "bracket" is a
pair of characters to be used as brackets surrounding the
disambiguator or empty to have no brackets.
"""
# Fast paths: no album, no item or library, or memoized value.
I don’t think that’s a viable option, since tmpl_aunique
isn’t a staticmethod, so requires the item and lib to construct the object, which I doubt you can do from inside an inline python block. Is that correct, or is there a way to get to the library object from album_fields
?
Indeed—it’s certainly not easily done, but perhaps with enough hacking you can construct your own Library
object, linked to the appropriate database, to obtain the object you need.
This question came up again in another topic, with a solution posted there:
Changed my code to
initial: |
import beets.plugins
the_func = beets.plugins.template_funcs()['the']
the_artist = the_func(albumartist_sort or artist_sort or albumartist or artist or '_')
return the_artist[0].upper()
And this works like a charm. Thanks!
1 Like