From a00e56f2193b05654921b0b5c5d0a41337384b19 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 14 Sep 2021 22:44:56 +0200 Subject: [PATCH] lol it works --- bin/mtag/README.md | 5 +++ bin/mtag/wget.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 bin/mtag/wget.py diff --git a/bin/mtag/README.md b/bin/mtag/README.md index fb418120..9a7e27b8 100644 --- a/bin/mtag/README.md +++ b/bin/mtag/README.md @@ -6,6 +6,11 @@ some of these rely on libraries which are not MIT-compatible * [audio-key.py](./audio-key.py) detects the melodic key of music using the Mixxx fork of keyfinder; imports GPL3 * [media-hash.py](./media-hash.py) generates checksums for audio and video streams; uses FFmpeg (LGPL or GPL) +these do not have any problematic dependencies: + +* [exe.py](./exe.py) grabs metadata from .exe and .dll files (example for retrieving multiple tags with one parser) +* [wget.py](./wget.py) lets you download files by POSTing URLs to copyparty + # dependencies diff --git a/bin/mtag/wget.py b/bin/mtag/wget.py new file mode 100644 index 00000000..623e9b3b --- /dev/null +++ b/bin/mtag/wget.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +""" +use copyparty as a file downloader by POSTing URLs as +application/x-www-form-urlencoded (for example using the +message/pager function on the website) + +example copyparty config to use this: + --urlform save,get -vsrv/wget:wget:rwmd,ed:c,e2ts:c,mtp=title=ebin,t300,ad,bin/mtag/wget.py + +explained: + for realpath srv/wget (served at /wget) with read-write-modify-delete for ed, + enable file analysis on upload (e2ts), + use mtp plugin "bin/mtag/wget.py" to provide metadata tag "title", + do this on all uploads with the file extension "bin", + t300 = 300 seconds timeout for each dwonload, + ad = parse file regardless if FFmpeg thinks it is audio or not +""" + + +import os +import sys +import subprocess as sp +from urllib.parse import unquote_to_bytes as unquote + + +def main(): + fp = sys.argv[1] + fdir = os.path.dirname(fp) + fname = os.path.basename(fp) + if not fname.startswith("put-") or not fname.endswith(".bin"): + raise Exception("not a post file") + + buf = b"" + with open(fp, "rb") as f: + while True: + b = f.read(4096) + buf += b + if len(buf) > 4096: + raise Exception("too big") + + if not b: + break + + if not buf: + raise Exception("file is empty") + + buf = unquote(buf.replace(b"+", b" ")) + url = buf.decode("utf-8") + + if not url.startswith("msg="): + raise Exception("does not start with msg=") + + url = url[4:] + if "://" not in url: + url = "https://" + url + + os.chdir(fdir) + + name = url.split("?")[0].split("/")[-1] + tfn = "-- DOWNLOADING " + name + open(tfn, "wb").close() + + cmd = ["wget", "--trust-server-names", "--", url] + + try: + sp.check_call(cmd) + except: + open("-- FAILED TO DONWLOAD " + name, "wb").close() + + os.unlink(tfn) + print(url) + + +if __name__ == "__main__": + main()