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

45 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
DATAFILE="/opt/konyvleltar/data/moly.txt"
INPUTFILE="/opt/konyvleltar/data/moly-input-$RANDOM.txt"
ERRORFILE="/opt/konyvleltar/data/moly-error.txt"
LIBRARY="http://localhost:32452/#paperbooks"
META_TMP="/home/calibre/metamoly.tmp"
COVER_TMP="/home/calibre/covermoly.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 MOLYID
do
ALREADY_IN=`calibredb --with-library $LIBRARY list --fields id --search "identifiers:moly_hu:$MOLYID" | tail -n +2 | wc -l`
if [ $ALREADY_IN -eq 0 ];
then
fetch-ebook-metadata $RESTRICT_MOLY --identifier moly_hu:$MOLYID -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 --identifier moly_hu:$MOLYID $COVER dummy.paperbook
ID=`calibredb --with-library $LIBRARY list --fields id --search "identifiers:moly_hu:$MOLYID" | grep -v id`
calibredb --with-library $LIBRARY set_metadata $ID "$META_TMP"
else
echo $MOLYID >> $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