diff --git a/bin/thumbs/README.md b/bin/thumbs/README.md index b3765418..87f2dfee 100644 --- a/bin/thumbs/README.md +++ b/bin/thumbs/README.md @@ -46,6 +46,8 @@ copyparty performs buffered reading, so expect multiple `read()` calls, respect ## examples +* [randomcolor](https://github.com/9001/copyparty/blob/hovudstraum/bin/thumbs/randomcolor.py) generates a random .gif image + ## some other known plugins seen on the internets diff --git a/bin/thumbs/randomcolor.py b/bin/thumbs/randomcolor.py new file mode 100644 index 00000000..61375cc0 --- /dev/null +++ b/bin/thumbs/randomcolor.py @@ -0,0 +1,29 @@ +import io +import os +import struct +from base64 import b64decode + + +def create_gif() -> bytes: + head = r"R0lGODdhIAAgAIAB" + tail = r"AAD/LAAAAAAgACAAAAIehI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC5sFADs=" + #color = struct.pack(">L", random.randrange(0xffffff)) # wow, way too stable + color = b"\x00" + os.urandom(3) + return b64decode(head) + color + b64decode(tail) + + +def main(abspath, **ka) -> Optional[tuple[str, IO[bytes], int, int, Optional[int]]]: + print("hello from randomcolor.py pretending to extract a thumb from " + abspath) + + # need to return a file-like object + gif_bytes = create_gif() + file_obj = io.BytesIO(gif_bytes) + + # where copyparty should seek to in the "file" to start reading from + seek_offset = 0 + seek_whence = 0 + + filesize = None # auto; read until end + + # "gif" is the file-extension to decode the file as + return "gif", file_obj, seek_offset, seek_whence, filesize diff --git a/copyparty/__main__.py b/copyparty/__main__.py index a7ca7905..0910be10 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -778,7 +778,7 @@ def get_sects(): + build_flags_desc(), ], [ - "thumb-extractors", + "thumb-ex", "extract thumbnails from custom file formats with python scripts", dedent( """ @@ -1896,7 +1896,7 @@ def add_thumbnail(ap): ap2.add_argument("--th-spec-cnv", metavar="T", type=u, default="it,itgz,itxz,itz,mdgz,mdxz,mdz,mo3,mod,s3m,s3gz,s3xz,s3z,xm,xmgz,xmxz,xmz,xpk", help="audio formats which provoke https://trac.ffmpeg.org/ticket/10797 (huge ram usage for s3xmodit spectrograms)") ap2.add_argument("--au-unpk", metavar="E=F.C", type=u, default="mdz=mod.zip, mdgz=mod.gz, mdxz=mod.xz, s3z=s3m.zip, s3gz=s3m.gz, s3xz=s3m.xz, xmz=xm.zip, xmgz=xm.gz, xmxz=xm.xz, itz=it.zip, itgz=it.gz, itxz=it.xz, cbz=jpg.cbz, epub=jpg.epub, kra=png.kra, ora=png.ora", help="audio/image formats to decompress before passing to ffmpeg") - ap2.add_argument("--th-extract", metavar="T", type=u, action="append", help="\033[34mREPEATABLE:\033[0m list of file extensions to thumbnail using a custom plugin (a python script); example: [\033[32mmdf,iso,dmg=/handlers/th_diskimg.py\033[0m]") + ap2.add_argument("--th-extract", metavar="T", type=u, action="append", help="\033[34mREPEATABLE:\033[0m list of file extensions to thumbnail using a custom plugin (a python script); example: [\033[32mmdf,iso,dmg=/thumbs/diskimg.py\033[0m], see --help-thumb-ex") ap2.add_argument("--th-extr-sz", metavar="M", type=int, default=16, help="max num megabytes to allow \033[33m--th-extract\033[0m plugins to extract from each file") ap2.add_argument("--hot-th-extr", action="store_true", help="recompile extractors on each thumbnail extraction -- expensive but convenient when hacking on stuff") diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 02ced1e6..aa2fd67f 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -562,12 +562,10 @@ class ThumbSrv(object): ext = ap_extr.rsplit(".", 1)[-1] if ext in self.args.au_unpk: - ap_unpk = au_unpk(self.log, self.args.au_unpk, abspath, vn) ap_unpk = au_unpk(self.log, self.args.au_unpk, ap_extr, vn) elif ext in self.thumbable_native: ap_unpk = ap_extr else: - ap_unpk = abspath ap_unpk = "" if ap_extr and ap_extr != ap_unpk and ap_extr != abspath: diff --git a/scripts/genhelp.sh b/scripts/genhelp.sh index 5d9a7a7c..6e8792b3 100755 --- a/scripts/genhelp.sh +++ b/scripts/genhelp.sh @@ -15,7 +15,7 @@ command -v gsort >/dev/null && { cd ../dist -kwds='-bind -accounts -auth -auth-ord -flags -handlers -hooks -idp -urlform -exp -rlo -ls -dbd -chmod -pwhash -zm' +kwds='-bind -accounts -auth -auth-ord -flags -thumb-ex -handlers -hooks -idp -urlform -exp -rlo -ls -dbd -chmod -pwhash -zm' export PRTY_FULL_HELP=1 export PRTY_NO_PARAMIKO=1