From d865e9f35a4764d0fce9155d231a2123b22859ce Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 9 Oct 2021 22:09:35 +0200 Subject: [PATCH] support non-python mtp plugins --- README.md | 20 ++++++++++++++++++++ copyparty/mtag.py | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b1a625e..14db3f1d 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ turn your phone or raspi into a portable file server with resumable uploads/down * [database location](#database-location) - in-volume (`.hist/up2k.db`, default) or somewhere else * [metadata from audio files](#metadata-from-audio-files) - set `-e2t` to index tags on upload * [file parser plugins](#file-parser-plugins) - provide custom parsers to index additional tags + * [upload events](#upload-events) - trigger a script/program on each upload * [complete examples](#complete-examples) * [browser support](#browser-support) - TLDR: yes * [client examples](#client-examples) - interact with copyparty using non-browser clients @@ -699,6 +700,25 @@ copyparty can invoke external programs to collect additional metadata for files * `-mtp arch,built,ver,orig=an,eexe,edll,~/bin/exe.py` runs `~/bin/exe.py` to get properties about windows-binaries only if file is not audio (`an`) and file extension is exe or dll +## upload events + +trigger a script/program on each upload like so: + +``` +-v /mnt/inc:inc:w:c,mte=+a1:c,mtp=a1=ad,/usr/bin/notify-send +``` + +so filesystem location `/mnt/inc` shared at `/inc`, write-only for everyone, appending `a1` to the list of tags to index, and using `/usr/bin/notify-send` to "provide" that tag + +that'll run the command `notify-send` with the path to the uploaded file as the first and only argument (so on linux it'll show a notification on-screen) + +note that it will only trigger on new unique files, not dupes + +and it will occupy the parsing threads, so fork anything expensive, or if you want to intentionally queue/singlethread you can combine it with `--no-mtag-mt` + +if this becomes popular maybe there should be a less janky way to do it actually + + ## complete examples * read-only music server with bpm and key scanning diff --git a/copyparty/mtag.py b/copyparty/mtag.py index 5725ba21..9a5e5066 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -471,7 +471,10 @@ class MTag(object): ret = {} for tagname, mp in parsers.items(): try: - cmd = [sys.executable, mp.bin, abspath] + cmd = [mp.bin, abspath] + if mp.bin.endswith(".py"): + cmd = [sys.executable] + cmd + args = {"env": env, "timeout": mp.timeout} if WINDOWS: