Perform template field substitution on albums

- adds another traversal through all plugins' template_fields for each
  'evaluate_template' call.
- requires the following idiom (or equivalent):

    @Plugin.template_field(field')
    def _tmpl_field(album):
        """Return stuff.
        """
        if isinstance(album, Album):
            return stuff
This commit is contained in:
Pedro Silva 2013-05-15 12:58:52 +01:00
parent 9dd5e84c60
commit 106ad99556
2 changed files with 15 additions and 0 deletions

View file

@ -1754,6 +1754,10 @@ class Album(BaseAlbum):
mapping['artpath'] = displayable_path(mapping['artpath'])
mapping['path'] = displayable_path(self.item_dir())
# Get values from plugins.
for key, value in plugins.template_values(self).iteritems():
mapping[key] = value
# Get template functions.
funcs = DefaultTemplateFunctions().functions()
funcs.update(plugins.template_funcs())

View file

@ -261,6 +261,17 @@ that adds a ``$disc_and_track`` field::
With this plugin enabled, templates can reference ``$disc_and_track`` as they
can any standard metadata field.
Note that the above idiom expects the argument ``item`` to be an
actual *track* item. If you'd like to provide a template field for
*albums*, you'll need to check the argument::
@MyPlugin.template_field('field')
def _tmpl_field(album):
"""Return stuff.
"""
if isinstance(album, beets.library.Album):
return 'stuff'
Extend MediaFile
^^^^^^^^^^^^^^^^