Here's the script:
Code: Select all
#!/bin/sh
#cbz cbr thumbnailer made to be used this way: cbz_thumbnailer.sh input (%i) size (%s) output (%o)
#dependencies: unzip unrar file imagemagick awk
TMP_FILE="/tmp/cbz_thumbnailer_tmp"
LOG_FILE="/tmp/cbz_thumbnailer.log"
if [ ! -e "$3" ]
then
echo "$3 doesn't exist" >> $LOG_FILE
else
echo "$3 already exist" >> $LOG_FILE
exit 1
fi
case $(file -b --mime-type "$1") in
application/zip )
FIRST_IMAGE="$(unzip -l "$1" | awk 'NR==4 {print $4}')"
[ "$FIRST_IMAGE" = "" ] && echo "$1 is empty" >> $LOG_FILE && exit 1
unzip -p "$1" "$FIRST_IMAGE" > $TMP_FILE
;;
application/x-rar )
FIRST_IMAGE="$(unrar lb "$1" | awk 'NR==1')"
unrar p -inul "$1" "$FIRST_IMAGE" > $TMP_FILE
;;
* )
echo "$1 is not a zip nor a rar file" >> $LOG_FILE
exit 1
;;
esac
case $(file -b --mime-type $TMP_FILE) in
image/png | image/jpeg )
convert -define jpeg:size='512x512' $TMP_FILE -thumbnail "$2x$2" "$3"
;;
* )
echo "The first file of $1 isn't an image (png/jpeg)" >> $LOG_FILE
exit 1
;;
esac
rm "$TMP_FILE"
Code: Select all
[Thumbnailer Entry]
TryExec=cbz_cbr_thumbnailer.sh
Exec=cbz_cbr_thumbnailer.sh %i %s %o
MimeType=application/x-cbz;application/x-cbr;
I'm at loss for words. Thanks for your attention.