-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepub2cbz.sh
executable file
·36 lines (28 loc) · 992 Bytes
/
epub2cbz.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
###
### Extracts images from an epub file and packages them into a cbz file.
###
### Usage:
### epub2cbz <input> <output>
###
### Options:
### <input> Input epub file with images.
### <output> Output cbz file
### -h, --help Show this message.
# Exit on error
set -euo pipefail
if [[ $# -ne 2 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
sed -rn 's/^### ?//;T;p' "$0"
exit 1
fi
ANSI_RESET="\033[0m"
ANSI_BRIGHT_BLACK="\033[90m"
WORK_DIR="$(mktemp --directory -t epub2cbz_XXXXXX)"
trap 'rm -rf -- "${WORK_DIR}"' EXIT
mkdir "${WORK_DIR}/step2"
echo -e "${ANSI_BRIGHT_BLACK}(Step 1/3)${ANSI_RESET} Converting epub to pdf..."
ebook-convert "$1" "${WORK_DIR}/step1.pdf" --pdf-no-cover
echo -e "${ANSI_BRIGHT_BLACK}(Step 2/3)${ANSI_RESET} Extracting images from pdf..."
pdfimages -all "${WORK_DIR}/step1.pdf" "${WORK_DIR}/step2/page"
echo -e "${ANSI_BRIGHT_BLACK}(Step 3/3)${ANSI_RESET} Packaging cbz file..."
zip -jr0 "$2" "${WORK_DIR}/step2"/*