Add initial working version
This commit is contained in:
commit
584242bf0a
3 changed files with 68 additions and 0 deletions
11
README.md
Normal file
11
README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
```
|
||||
1. Copy the beets plugin into your plugin folder (e.g. /usr/lib64/python2.7/site-packages/beetsplug/)
|
||||
2. Deploy the virtual-env wrapper (auto_deploy.sh) e.g. to /opt/funkwhale/auto_deploy.sh and adjust paths in it
|
||||
3. Adjust your beets config for the plugin:
|
||||
|
||||
plugins: funkwhaleimport
|
||||
funkwhale:
|
||||
library_id: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
|
||||
importer: "/opt/funkwhale/auto_import.sh"
|
||||
|
||||
```
|
13
auto_import.sh
Executable file
13
auto_import.sh
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
USER=$(id -un)
|
||||
if [ "$USER" != "funkwhale" ]; then
|
||||
exec sudo -u funkwhale $0 "$@"
|
||||
elif [ "$USER" == "funkwhale" ]; then
|
||||
echo "activating venv"
|
||||
cd /opt/funkwhale
|
||||
source virtualenv/bin/activate
|
||||
export $(cat prod.env)
|
||||
echo "venv activated. Importing now"
|
||||
echo "$@"
|
||||
exec /opt/funkwhale/api/manage.py "$@"
|
||||
fi
|
44
funkwhaleimport.py
Normal file
44
funkwhaleimport.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
# -*- 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)
|
Loading…
Reference in a new issue