Pour un besoin récent, j’avais besoin de retrouver tout les epub que j’avais acheter chez un vendeur d’epub qui n’existe plus (feedbooks). Du coup, j’ai fait un script pour aller chercher dans ma bibliothèque.
#!/bin/bash
if [ $# -lt 2 ]
then
echo
echo "Usage: ${0} <path-to-epub-directory (aka calibre root biblio)> <name to search>"
echo "export VERBOSE=1 to add verbosity or VERBOSE=1 ${0} ..."
echo
exit
fi
CUR_DIR=$(dirname "$0")
PATH_TO_SEARCH=$1
PATTERN_TO_SEARCH=$2
echo "Searching in ${PATH_TO_SEARCH} about ${PATTERN_TO_SEARCH}..."
mapfile FILES < <(find "$PATH_TO_SEARCH" -type f -name '*.epub')
N="${#FILES[@]}"
echo "... found ${N} epubs!"
for ((I=0; I<N; I++))
do
epub_file=$(echo "${CUR_DIR}/${FILES[$I]}" | sed 's/\n//')
fileloc=$(unzip -l "${epub_file}" | grep -o 'OEBPS/.*.xhtml')
found=0
for xhtml in $fileloc
do
metafound=$(zipgrep "${PATTERN_TO_SEARCH}" "${epub_file}" "${xhtml}")
if [ "$metafound" != "" ]; then
# display only once that we have found it
if [[ "$found" -eq "0" ]]; then
echo "Found in ${epub_file}"
fi
found=1
if [[ "$VERBOSE" -eq "1" ]]; then
printf "\t|_ %s\n" "$metafound"
else
break
fi
fi
done
done
echo
echo 'EOL'
echo
exit
On ne sait jamais que cela vous serve