# -*- coding: utf-8 -*- """Updates an Funkwhale intance whenever the filesystem changes. Put something like the following in your config.yaml to configure: funkwhale: library_id: id_to_import_into importer: path_to_importer_script """ from __future__ import division, absolute_import, print_function from beets.plugins import BeetsPlugin import os from beets import config from subprocess import call class FunkwhaleUpdatePlugin(BeetsPlugin): def __init__(self): super(FunkwhaleUpdatePlugin, self).__init__() config['funkwhale'].add({ "library_id": "", "importer": "" }) self.register_listener('import_task_files', self.task_done) def task_done(self, task, session): self._log.info(u'Database updated.') folders = [] for item in task.items: path = os.path.dirname(item.path) #get path of every imported file folders.append(path) folders = list(set(folders)) folders = map(lambda f: os.path.join(f, "*"), folders) command = [ str(config["funkwhale"]["importer"]), "import_files", str(config["funkwhale"]["library_id"]), " ".join(map(lambda f: "{}".format(f),folders)), "--recursive", "--replace", "--noinput" ] call(command)