Created
October 28, 2020 15:17
-
-
Save garbled1/be65b6a478d0d77f6e9f94a7a213025f to your computer and use it in GitHub Desktop.
Download webcomics with dosage into CBZ files nightly. Uses to_cbz and dosage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source ~/venv/bin/activate | |
rm /comics/download/WebToons/*/complete.txt | |
dosage -b /comics/download -c @ | |
COMIC_DL=/comics/download | |
COMIC_CBZ=/comics/cbz | |
COMIC_TMP=/comics/tmp | |
SPLIT_BY=30 | |
if [ ! -d ${COMIC_CBZ} ]; then | |
mkdir ${COMIC_CBZ} | |
fi | |
if [ ! -d ${COMIC_TMP} ]; then | |
mkdir ${COMIC_TMP} | |
fi | |
#for cm_dir in `ls -1d ${COMIC_DL}/*` | |
for cm_dir in `find ${COMIC_DL} -type d | tail -n +2` | |
do | |
comic=$(basename ${cm_dir}) | |
FIRSTFILE=$(ls -1 ${cm_dir} | head -1) | |
if [ -d "${FIRSTFILE}" ]; then | |
# this is a subdir, not a comic | |
continue | |
fi | |
echo "Working on ${comic}" | |
if [ ! -d ${COMIC_CBZ}/${comic} ]; then | |
mkdir ${COMIC_CBZ}/${comic} | |
fi | |
# Switch out for different comics to be fancy | |
case "${cm_dir}" in | |
*WebToons*) | |
# Not yet | |
# example: /comics/download/WebToons/TheGamer/342-00.jpg | |
EP_LIST=$(ls -1 ${cm_dir} | grep -v complete | sed -e 's/\([0-9]*\)-.*/\1/' | sort -nu) | |
LAST_EP=$(ls -1 ${cm_dir} | grep -v complete | sed -e 's/\([0-9]*\)-.*/\1/' | sort -nu | tail -1) | |
for ep in ${EP_LIST} | |
do | |
echo "Found ${comic} ep ${ep}" | |
# clear out tmpdirs | |
rm -rf ${COMIC_TMP}/${comic} | |
mkdir ${COMIC_TMP}/${comic} | |
cd ${cm_dir} | |
if [ $ep -eq ${LAST_EP} ]; then | |
# don't erase the last ep, so we keep dosage working | |
cp ${cm_dir}/${ep}-* ${COMIC_TMP}/${comic} | |
else | |
#mv | |
mv ${cm_dir}/${ep}-* ${COMIC_TMP}/${comic} | |
fi | |
LONG_COUNT=$(printf "%0.4d" ${ep}) | |
echo "Creating ${COMIC_CBZ}/${comic}/${comic}-${LONG_COUNT}.cbz" | |
cd ${COMIC_TMP} | |
rm -f ${COMIC_TMP}/${comic}.cbz | |
/home/cbdl/venv/bin/to_cbz.py ${comic} | |
if [ ! -f ${COMIC_TMP}/${comic}.cbz ]; then | |
echo "FATAL ERROR" | |
exit 1 | |
fi | |
mv ${COMIC_TMP}/${comic}.cbz ${COMIC_CBZ}/${comic}/${comic}-${LONG_COUNT}.cbz | |
done | |
;; #WebToons | |
*) | |
# Std set of X handling | |
COUNT=$(ls -1tr ${cm_dir}/ | tail -${SPLIT_BY} | wc -l) | |
while [ ${COUNT} -eq ${SPLIT_BY} ] | |
do | |
# If we have exactly ${SPLIT_BY} we break dosage -c | |
SAFETY_CHECK=$(ls -1tr ${cm_dir}/ | wc -l) | |
if [ ${SAFETY_CHECK} -eq ${SPLIT_BY} ]; then | |
break; | |
fi | |
# clear out tmpdirs | |
rm -rf ${COMIC_TMP}/${comic} | |
mkdir ${COMIC_TMP}/${comic} | |
# get current count | |
CBZ_COUNT=$(ls -1tr ${COMIC_CBZ}/${comic}/${comic}-[0-9][0-9][0-9][0-9].cbz | wc -l) | |
X_COUNT=$(( ${CBZ_COUNT} + 1 )) | |
LONG_COUNT=$(printf "%0.4d" ${X_COUNT}) | |
echo "Creating ${COMIC_CBZ}/${comic}/${comic}-${LONG_COUNT}.cbz" | |
FILES=$(ls -1tr ${cm_dir}/ | tail -${SPLIT_BY} | tac) | |
cd ${cm_dir} | |
bcount=0 | |
for ff in ${FILES} | |
do | |
ext="${ff##*.}" | |
bcount=$(( ${bcount} + 1 )) | |
pp=$(printf "%0.2d" ${bcount}) | |
echo "mv Page-${pp}.${ext} ${ff}" >> ${COMIC_TMP}/${comic}/orignames.sh | |
mv ${ff} ${COMIC_TMP}/${comic}/Page-${pp}.${ext} | |
done | |
cd ${COMIC_TMP} | |
rm -f ${COMIC_TMP}/${comic}.cbz | |
/home/cbdl/venv/bin/to_cbz.py ${comic} | |
if [ ! -f ${COMIC_TMP}/${comic}.cbz ]; then | |
echo "FATAL ERROR" | |
exit 1 | |
fi | |
mv ${COMIC_TMP}/${comic}.cbz ${COMIC_CBZ}/${comic}/${comic}-${LONG_COUNT}.cbz | |
COUNT=$(ls -1tr ${cm_dir}/ | tail -${SPLIT_BY} | wc -l) | |
done | |
FINDIR=$(find ${cm_dir} -maxdepth 1 -type f | wc -l) | |
# Deal with the partial | |
if [ ${COUNT} -gt 0 -a ${FINDIR} -gt 0 ]; then | |
echo "Found a partial.." | |
rm -rf ${COMIC_TMP}/${comic} | |
mkdir ${COMIC_TMP}/${comic} | |
FILES=$(ls -1tr ${cm_dir}/ | tac) | |
cd ${cm_dir} | |
cp ${FILES} ${COMIC_TMP}/${comic} | |
cd ${COMIC_TMP} | |
rm -f ${COMIC_TMP}/${comic}.cbz | |
/home/cbdl/venv/bin/to_cbz.py ${comic} | |
mv ${COMIC_TMP}/${comic}.cbz ${COMIC_CBZ}/${comic}/${comic}-9999.cbz | |
fi | |
rm -rf ${COMIC_TMP}/${comic} | |
;; #* | |
esac | |
echo "Done with ${comic}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment