Add epub exctraction script

This commit is contained in:
RealStickman 2022-05-10 13:49:42 +02:00
parent 6795a0e703
commit ece39ef84d

30
arch-config/scripts/pieces/manga-extract-epub.sh Normal file → Executable file
View File

@ -1,8 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
if [ $# -ne 1 ]; then
echo "Please use this script with a \"PATH\" to a folder containing Manga chapters"
$(exit 1); echo "$?"
fi
dir="$1"
parentdir="$(dirname "$dir")"
filename="$(basename "$dir")"
# remove .epub to get output folder name
outdir="${filename%.*}"
cd "$parentdir"
#echo $parentdir
#echo $filename
#echo $outdir
# 1. extract .epub
unzip "$dir" -d "$outdir"
# 2. images under "(folder name)/OEBPS/image"
# 3. rename images to "pageXXX.(ext)"
# 4. move to "(folder name)"
# 5. delete folders "META-INF", "OEBPS" and file "mimetype"
mv "$outdir/OEBPS/image/"* "$outdir/"
# 3. delete folders "META-INF", "OEBPS" and file "mimetype"
rm -r "$outdir/"{META-INF,OEBPS,mimetype}
# 4. rename images to "pageXXX.(ext)"
cd "$outdir"
ls | cat -n | while read n f; do mv "$f" `printf "page%03d.jpg" $n`; done