#!/bin/bash
series="$1"
if [ -z "$1" ]
then read -p "series ? " series
fi
######## series page URL structure #######
#
# by default, the script checks manga from a specific series, filtering only english type. You can check ALL manga (including non-english) by removing "&type=english" from the URL. Also you can check only colored manga by adding "&type=color".
###########################################
mangacount=$(wget -q --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0" -O - "http://www.hentai.ms/manga?Series=$series&type=english" | grep -o -e '[0-9]* hentai mangas from' | sed 's/[^0-9]*//g')
pages=$(($mangacount/12+1))
echo "$series has $mangacount mangas ($pages pages)"
maxpage=$(($pages*12+1))
i=12
echo " -checking pages..."
while [ $i -lt $maxpage ]; do
echo " series: $series offset: $i"
wget -q --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0" -O - "http://www.hentai.ms/manga/&Series=$series&num=$i&type=english" | grep -o '> 'output.txt'
while read line; do
wget -q --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0" -O - "$line" | grep -o '> 'download.txt'
done < 'output.txt'
rm 'output.txt'
i=$((12+$i))
done
linecount=$(wc -l 'download.txt' | cut -f1 -d ' ')
echo "Done ! I've found $linecount mangas for you."
echo "================"
echo "Let's download !"
echo "================"
mkdir -p "$series"
count=0
while read line; do
wget -N -q --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0" --content-disposition -P "$series" "$line"
if [ -f "$series/index.html" ]; then echo "** WARNING: did not download properly: $line"; rm "$series/index.html"; fi
count=$(($count+1))
echo "ok: $count / $linecount"
done < 'download.txt'
rm 'download.txt'
echo "=== finished ! ==="