Merge pull request #274 from pedros/album_template_fields

Perform template field substitution on albums
This commit is contained in:
Adrian Sampson 2013-05-17 11:40:46 -07:00
commit 05cfbdcd0b
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
^^^^^^^^^^^^^^^^