]> zdv2.bktei.com Git - BK-2020-03.git/blob - user/htmlz_to_cbz.sh
update(user/htmlz_to_cbz.sh): Use jdupes to deduplicate images
[BK-2020-03.git] / user / htmlz_to_cbz.sh
1 #!/bin/bash
2 # Desc: Collects .jpg/jpeg files from a Calibre .htmlz file into .cbz files
3 # Version: 0.1.0
4 # Depends: jdupes 1.27.3
5
6 for fin in ./*.htmlz; do
7 (
8 dout="${fin%.*}";
9 unzip "$fin" -x / -d "$dout";
10 pushd "$dout";
11 mapfile -t images < <(cat index.html | grep -E "(.jpg|.jpeg)" | sed -E -e 's#.+(images/[0-9]+.(jpeg|jpg)).+#\1#' | uniq; );
12 dout="./output";
13 if [[ -d "$dout" ]]; then
14 rm -r "$dout";
15 fi;
16 mkdir "$dout";
17 n=1;
18 for path in "${images[@]}"; do
19 fnew="${dout}/$(printf "%06d" "$n").jpg";
20 cp "$path" "$fnew";
21 ((n++));
22 done;
23 # Add cover file if present
24 if [[ -f cover.jpg ]]; then
25 cp -n cover.jpg "${dout}/000000.jpg";
26 fi;
27 # Remove duplicate images
28 if command -v jdupes 1>/dev/random 2>&1; then
29 jdupes -dN "$dout";
30 fi;
31 faout="output.cbz";
32 if [[ -f "$faout" ]]; then
33 rm "$fout";
34 fi;
35 zip -j output.cbz "$dout"/*;
36 ) &
37 done;
38 wait && echo "STATUS:Finished." 1>&2;