configs/arch-config/scripts/pieces/manga-extract-epub.sh

40 lines
1003 B
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
2022-05-10 13:49:42 +02:00
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
2022-05-10 13:54:41 +02:00
rm -rf "$outdir"
# 1. extract .epub
2022-05-10 13:49:42 +02:00
unzip "$dir" -d "$outdir"
# 2. images under "(folder name)/OEBPS/image"
#mv "$outdir/OEBPS/image/"* "$outdir/"
mv "$outdir/images/"* "$outdir/"
2022-05-10 13:49:42 +02:00
# 3. delete folders "META-INF", "OEBPS" and file "mimetype"
rm -rf "$outdir/"{META-INF,OEBPS,mimetype,images,text,content.opf,page_styles.css,stylesheet.css,titlepage.xhtml,toc.ncx}
2022-05-10 13:49:42 +02:00
# 4. rename images to "pageXXX.(ext)"
cd "$outdir"
# if cover.jpg exists, rename it to be the first page
if [ -f cover.jpg ] || [ -f cover.jpeg ]; then
mv cover.* 0000000000.jpg
fi
2022-05-10 13:49:42 +02:00
ls | cat -n | while read n f; do mv "$f" `printf "page%03d.jpg" $n`; done