Skip to content

Commit

Permalink
batch-convert audio waveforms with ?tar&p
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed May 10, 2024
1 parent c046627 commit 38e4fdf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion copyparty/httpcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,7 @@ def tx_zip(
# 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

Expand Down
5 changes: 5 additions & 0 deletions copyparty/th_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def get(self, dbv: VFS, rem: str, mtime: float, fmt: str) -> Optional[str]:
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:
Expand Down
6 changes: 3 additions & 3 deletions copyparty/th_srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,6 @@ def worker(self) -> None:
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:
Expand All @@ -334,6 +331,9 @@ def worker(self) -> None:

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:
Expand Down
3 changes: 3 additions & 0 deletions docs/devnotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down

0 comments on commit 38e4fdf

Please sign in to comment.