1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00
nux-env/inc/thumby/builtin.nuxsh.sh
Tony Tkacik 4c4bb238a0 Legacy sync
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2020-03-05 12:20:11 +01:00

46 lines
1.5 KiB
Bash

@namespace thumby.thumb.source {
function :locator.directory {
nux.log info "Using find to find jpg or png"
find -L "$1" -maxdepth 1 -iname "*.jpg" -or -iname "*.png" | sort -n | head -n1
}
function :locator.application.pdf {
echo "$1[0]"
}
function :extractor.application.epub+zip() {
local rootDesc=$(unzip -p "$1" META-INF/container.xml \
| xmlstarlet sel -N od="urn:oasis:names:tc:opendocument:xmlns:container" \
-t -v "/od:container/od:rootfiles/od:rootfile[@media-type='application/oebps-package+xml']/@full-path" -n)
nux.log info "Root description is in: $rootDesc";
local imgDesc=$(unzip -p "$1" "$rootDesc" \
| xmlstarlet sel -N opf="http://www.idpf.org/2007/opf" \
-t -m "/opf:package/opf:manifest/opf:item[@id=/opf:package/opf:metadata/opf:meta[@name='cover']/@content]" \
-v "@href" -o ":" -v "@media-type" -n)
IFS=":" read -r img media <<< "$imgDesc";
nux.log info "Image name is $imgDesc $img";
if [ -n "$img" ]; then
unzip -p "$1" $img
fi
}
function :extractor.application.x-cbr() {
suffix="${1##*.}"
case "$suffix" in
zip) ;&
cbz)
potential=$(unzip -l "$1" | sed -re "s/^ *[0-9]+ +[0-9\\-]+ +[0-9:]+ +//gi" | grep -E '\.((jpg)|(png)|(jpeg))$' | sort -n | head -n 1)
nux.log debug "Potential preview is: $potential";
if [ -n "$potential" ]; then
unzip -p "$1" "$potential"
nux.log debug "Preview extracted."
fi
;;
*) nux.log error "$suffix is not supported."
esac
}
}