X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/f06d25b954d7fc046d0f0bbd641feb5df721efd6..71e0fc154695564592503078a950d6e57bb46d6d:/user/htmlz_to_cbz.sh diff --git a/user/htmlz_to_cbz.sh b/user/htmlz_to_cbz.sh index bf535f0..b1c450e 100755 --- a/user/htmlz_to_cbz.sh +++ b/user/htmlz_to_cbz.sh @@ -1,13 +1,14 @@ #!/bin/bash # Desc: Collects .jpg/jpeg files from a Calibre .htmlz file into .cbz files -# Version: 0.0.1 +# Version: 0.1.0 +# Depends: jdupes 1.27.3 for fin in ./*.htmlz; do ( dout="${fin%.*}"; unzip "$fin" -x / -d "$dout"; pushd "$dout"; - mapfile -t images < <(cat index.html | grep -E "(.jpg|.jpeg)" | sed -E -e 's#.+(images/[0-9]+.(jpeg|jpg)).+#\1#'); + mapfile -t images < <(cat index.html | grep -E "(.jpg|.jpeg)" | sed -E -e 's#.+(images/[0-9]+.(jpeg|jpg)).+#\1#' | uniq; ); dout="./output"; if [[ -d "$dout" ]]; then rm -r "$dout"; @@ -19,14 +20,19 @@ for fin in ./*.htmlz; do cp "$path" "$fnew"; ((n++)); done; + # Add cover file if present if [[ -f cover.jpg ]]; then - cp -n cover.jpg ./output/000000.jpg; + cp -n cover.jpg "${dout}/000000.jpg"; + fi; + # Remove duplicate images + if command -v jdupes 1>/dev/random 2>&1; then + jdupes -dN "$dout"; fi; faout="output.cbz"; if [[ -f "$faout" ]]; then rm "$fout"; fi; - zip -r output.cbz output; + zip -j output.cbz "$dout"/*; ) & done; wait && echo "STATUS:Finished." 1>&2;