2.7 KiB
thumbnail extractors
extract (or generate) thumbnails for custom file formats or override default thumbnail extraction for standard media files
usage
- load plugins with
--th-extract baz=~/dev/copyparty/bin/thumbs/randomcolor.pybazis the file extension (may be comma-separated list of extensions)- add multiple different extractor plugins by repeating the
--th-extractargument
api
in
each plugin must define a function main(abspath, **kwargs):
abspathis the path to a file to extract thumbnail forkwargscurrently receives these keyword arguments:vnis the VFS which contains the requested fileth_srvis an instance of copyparty/th_srv
out
the main() function must
- return
Noneor raise anExceptionin case it is unable to extract thumbnail - return tuple
fmt, stream, offset, whence, sizeotherwise:fmt: str– format (filename extension) of the thumbnail; should be one of the image formats supported by copyparty (see--th-r-*options)stream: IO[bytes]– binary file-like object supportingseek(),read(),close()methods; should contain extracted thumbnail imageoffset: int, whence: int– arguments tostream.seek(); copyparty will callstream.seek(offset, whence)once before starting reading the stream contentssize: int | None– number of bytes to read from thestream; ifsizeis negative orNone, copyparty will read until the end of the stream
notes
it is possible to extract or generate custom thumbnails for standard media files too,
e.g. run copyparty with --th-extract mp3,m4a,aac,flac,opus=~/dev/copyparty/bin/thumbs/my_custom_mp3_th_extractor.py and do your magic with audio file thumbnails
in case copyparty doesn't like the fmt option, it will close() the stream without ever calling seek() or read()
if your scenario involves heavy computation or i/o, it is better to defer the heavy parts until the first seek() or read() to avoid redundant work in case the result gets rejected based on fmt value
if you provide custom stream object:
copyparty performs buffered reading, so expect multiple read() calls, respect size argument in read(size) calls, and maintain correct seek position
examples
- randomcolor generates a random .gif image
some other known plugins seen on the internets
- fpkg_thumb extracts cover images from playstation4 software installation packages ("pkg" and "fpkg" files)