Skip to content

Instantly share code, notes, and snippets.

@Efreak
Last active October 23, 2021 13:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Efreak/75da094f0877f8fe34d55767c443a574 to your computer and use it in GitHub Desktop.
Save Efreak/75da094f0877f8fe34d55767c443a574 to your computer and use it in GitHub Desktop.

Process chapters downloaded by Tachiyomi into cbz files.

  • Optionally convert to cbz.

  • Requires termux.

  • cd into your Tachiyomi/downloads/SOURCE/TITLE folder before running--the script will identify source and title itself.

  • Note that termux does not have cwebp, it must be compiled/obtained elsewhere.

  • Also consider -near_lossless instead of -lossless.

  • THERE IS NO GUARANTEE THIS WILL WORK, OR THAT IT HAD NO TYPOS (I modified, working around a large number of symlinks and personal scripts I use, as well as changing the comments.

  • You are advised to back up your termux and Tachiyomi before runnin (/data/data/com.termux/files; /sdcard/Tachiyomi/downloads), and test on a single Tachiyomi chapter.

  • after running the script, manually check to make sure the chapters are in the correct order--the files are prefixed so they're opened in order by download/modification date, as not all titles are read in alphabetical order.

    • especially see insane tapastic comics that spell out their page numbers
    • worse yet, some that only include page number of current chapter, making it impossible to download at all grumble.
#!/data/data/com.termux/files/usr/bin/bash
tach="$HOME/storage/shared/Tachiyomi"
# set vars for source and title (parent folder and current folder names, language stripped)
source=$(basename "$(dirname "$PWD")"|sed -E 's/ \(...?)$//')
title=$(basename $PWD)
# make a corresponding folder in Tachiyomi's local folder
local="$tach/local/$source - $title"
mkdir -p "$local"
# initialize chapter number
chnum=1
# iterate through chapters/folders in order by timestamp
ls -t|while read chapter
do
# run cwebp on the chapter first.
#cd "$chapter"
#for file in *.png *.gif
#do
# cwebp -hint picture -mt -m 6 -lossless -z -9 -noalpha -progress $file -o $file.webp
# rm $file
#done
#for file in *.jpg *.jpeg
#do
# cwebp -hint picture -mt -m 6 -q 85 -progress $file -o $file.webp
#. rm $file
#cd ..
# filename/path for current chapter. prefix name with chnum, padded to 3 digits
cbz="$local/$(printf "%03d" $chnum) - $chapter.cbz"
# make cbz for chapter, deleting original (`-sdel`)
7z a -tzip -mx0 -sdel "$cbz" "$chapter"
# increment chnum
((chnum++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment