From 38e4fdfe03fe3de3a9a8bbea4c869c46db384d0d Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 10 May 2024 12:55:35 +0000 Subject: [PATCH] batch-convert audio waveforms with `?tar&p` --- README.md | 2 +- copyparty/httpcli.py | 2 +- copyparty/th_cli.py | 5 +++++ copyparty/th_srv.py | 6 +++--- docs/devnotes.md | 3 +++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 03c56262..41e26719 100644 --- a/README.md +++ b/README.md @@ -615,7 +615,7 @@ you can also zip a selection of files or folders by clicking them in the browser cool trick: download a folder by appending url-params `?tar&opus` or `?tar&mp3` to transcode all audio files (except aac|m4a|mp3|ogg|opus|wma) to opus/mp3 before they're added to the archive * super useful if you're 5 minutes away from takeoff and realize you don't have any music on your phone but your server only has flac files and downloading those will burn through all your data + there wouldn't be enough time anyways -* and url-params `&j` / `&w` produce jpeg/webm thumbnails/spectrograms instead of the original audio/video/images +* and url-params `&j` / `&w` produce jpeg/webm thumbnails/spectrograms instead of the original audio/video/images (`&p` for audio waveforms) * can also be used to pregenerate thumbnails; combine with `--th-maxage=9999999` or `--th-clean=0` diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index b5d34861..191c9a59 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -3413,7 +3413,7 @@ class HttpCli(object): # for f in fgen: print(repr({k: f[k] for k in ["vp", "ap"]})) cfmt = "" if self.thumbcli and not self.args.no_bacode: - for zs in ("opus", "mp3", "w", "j"): + for zs in ("opus", "mp3", "w", "j", "p"): if zs in self.ouparam or uarg == zs: cfmt = zs diff --git a/copyparty/th_cli.py b/copyparty/th_cli.py index e137b89b..285d4a48 100644 --- a/copyparty/th_cli.py +++ b/copyparty/th_cli.py @@ -106,6 +106,11 @@ class ThumbCli(object): sfmt += "3" if "3" in fmt else "" fmt = sfmt + + elif fmt[:1] == "p" and not is_au: + t = "cannot thumbnail [%s]: png only allowed for waveforms" + self.log(t % (rem), 6) + return None histpath = self.asrv.vfs.histtab.get(ptop) if not histpath: diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 2878ed82..3208ec12 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -322,9 +322,6 @@ class ThumbSrv(object): else: funs.append(self.conv_spec) - if not png_ok and tpath.endswith(".png"): - raise Pebkac(400, "png only allowed for waveforms") - tdir, tfn = os.path.split(tpath) ttpath = os.path.join(tdir, "w", tfn) try: @@ -334,6 +331,9 @@ class ThumbSrv(object): for fun in funs: try: + if not png_ok and tpath.endswith(".png"): + raise Exception("png only allowed for waveforms") + fun(ap_unpk, ttpath, fmt, vn) break except Exception as ex: diff --git a/docs/devnotes.md b/docs/devnotes.md index 10a14a2d..1625871c 100644 --- a/docs/devnotes.md +++ b/docs/devnotes.md @@ -134,6 +134,9 @@ authenticate using header `Cookie: cppwd=foo` or url param `&pw=foo` | GET | `?zip=utf-8` | ...as a zip file | | GET | `?zip` | ...as a WinXP-compatible zip file | | GET | `?zip=crc` | ...as an MSDOS-compatible zip file | +| GET | `?tar&w` | pregenerate webp thumbnails | +| GET | `?tar&j` | pregenerate jpg thumbnails | +| GET | `?tar&p` | pregenerate audio waveforms | | GET | `?ups` | show recent uploads from your IP | | GET | `?ups&filter=f` | ...where URL contains `f` | | GET | `?mime=foo` | specify return mimetype `foo` |