From 2fae94a93a6c234c1dd1be36e2d6ea087eabc140 Mon Sep 17 00:00:00 2001 From: David Logie Date: Mon, 19 Jan 2015 13:44:14 +0000 Subject: [PATCH] Make the Template object an attribute. --- beetsplug/mbsync.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/beetsplug/mbsync.py b/beetsplug/mbsync.py index 95ca15c51..9f22d8fae 100644 --- a/beetsplug/mbsync.py +++ b/beetsplug/mbsync.py @@ -62,17 +62,18 @@ class MBSyncPlugin(BeetsPlugin): pretend = opts.pretend write = opts.write query = ui.decargs(args) - tmpl = Template(ui._pick_format(True, opts.format)) - self.singletons(lib, query, move, pretend, write, tmpl) - self.albums(lib, query, move, pretend, write, tmpl) + self.template = Template(ui._pick_format(True, opts.format)) - def singletons(self, lib, query, move, pretend, write, tmpl): + self.singletons(lib, query, move, pretend, write) + self.albums(lib, query, move, pretend, write) + + def singletons(self, lib, query, move, pretend, write): """Retrieve and apply info from the autotagger for items matched by query. """ for item in lib.items(query + ['singleton:true']): - item_formatted = item.evaluate_template(tmpl) + item_formatted = item.evaluate_template(self.template) if not item.mb_trackid: self._log.info(u'Skipping singleton with no mb_trackid: {0}', item_formatted) @@ -91,13 +92,13 @@ class MBSyncPlugin(BeetsPlugin): autotag.apply_item_metadata(item, track_info) apply_item_changes(lib, item, move, pretend, write) - def albums(self, lib, query, move, pretend, write, tmpl): + def albums(self, lib, query, move, pretend, write): """Retrieve and apply info from the autotagger for albums matched by query and their items. """ # Process matching albums. for a in lib.albums(query): - album_formatted = a.evaluate_template(tmpl) + album_formatted = a.evaluate_template(self.template) if not a.mb_albumid: self._log.info(u'Skipping album with no mb_albumid: {0}', album_formatted)