]> zdv2.bktei.com Git - BK-2020-03.git/blob - user/htmlz_to_cbz.sh
fix(user/bkdatev):Make tzdata-legacy 'right/UTC' TZ optional
[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.2
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|.png)" | sed -E -e 's#.+(images/[0-9]+.(jpeg|jpg|png)).+#\1#' | uniq; );
12 dout2="./output";
13 if [[ -d "$dout2" ]]; then
14 rm -r "$dout2";
15 fi;
16 mkdir "$dout2";
17 n=1;
18 for path in "${images[@]}"; do
19 fnew="${dout2}/$(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 "${dout2}/000000.jpg";
26 fi;
27 # Remove duplicate images
28 if command -v jdupes 1>/dev/random 2>&1; then
29 jdupes -dN "$dout2";
30 fi;
31 faout="output.cbz";
32 if [[ -f "$faout" ]]; then
33 rm "$fout";
34 fi;
35 zip -j output.cbz "$dout2"/*;
36 ) &
37 done;
38 wait && echo "STATUS:Finished." 1>&2;