konyvleltar/scripts/import-paperbooks.sh
2021-12-20 12:50:53 +01:00

45 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
DATAFILE="/opt/konyvleltar/data/isbn.txt"
INPUTFILE="/opt/konyvleltar/data/isbn-input-$RANDOM.txt"
ERRORFILE="/opt/konyvleltar/data/isbn-error.txt"
LIBRARY="http://localhost:32452/#paperbooks"
META_TMP="/home/calibre/meta.tmp"
COVER_TMP="/home/calibre/cover.jpg"
DUPES="-d" # "" or "-d"
RESTRICT_MOLY="" # "" or "--allowed-plugin Moly_hu"
if [ -f "$DATAFILE" ];
then
mv "$DATAFILE" "$INPUTFILE"
if [ -f "$META_TMP" ]; then rm "$META_TMP"; fi;
if [ -f "$COVER_TMP" ]; then rm "$COVER_TMP"; fi;
cat "$INPUTFILE" | while read ISBN
do
ALREADY_IN=`calibredb --with-library $LIBRARY list --fields isbn --search isbn:$ISBN | grep -v isbn | wc -l`
if [ $ALREADY_IN -eq 0 ];
then
fetch-ebook-metadata $RESTRICT_MOLY --isbn $ISBN -c "$COVER_TMP" -o > "$META_TMP"
if [ -s "$META_TMP" ]; # not empty
then
if [ -s "$COVER_TMP" ]; # not empty
then
COVER="--cover $COVER_TMP"
else
COVER=""
fi
calibredb --with-library $LIBRARY add $DUPES --isbn $ISBN $COVER dummy.paperbook
ID=`calibredb --with-library $LIBRARY list --fields id --search isbn:$ISBN | grep -v id`
calibredb --with-library $LIBRARY set_metadata $ID "$META_TMP"
else
echo $ISBN >> $ERRORFILE
fi
if [ -f "$META_TMP" ]; then rm "$META_TMP"; fi;
if [ -f "$COVER_TMP" ]; then rm "$COVER_TMP"; fi;
fi
done
rm $INPUTFILE
fi