ZSHFiles/custom/functions/getnhentai

19 lines
804 B
Plaintext

local pageinfo="$(curl -sL $1 | grep -oP '(?<=var gallery = new N.gallery\().*(?=\);)' | jq '{"pages": .num_pages,"id": .media_id, "types": [.images.pages[].t], "title": .title.pretty}')"
local media_id=$(print $pageinfo | jq -r '.id')
local types=($(print $pageinfo | jq -r '.types[]'))
local num_pages=$(print $pageinfo | jq '.pages')
local dir=$(print $pageinfo | jq -r '.title')
local urls=()
[ ! -z $2 ] && mkdir "$dir" && cd "$dir"
for i in {1..$num_pages}; do
local ctoi=$(($i - 1))
[[ ${types[$ctoi]} == p ]] && local type=png || local type=jpg
urls+=("https://i.nhentai.net/galleries/$media_id/$i.$type")
done
curl --retry 10 -\#L --remote-name-all ${urls}
for i in *; do
local sortname="$(printf "%.3i" "${i%%.*}").${i##*.}"
[ $sortname = $i ] || mv $i $sortname
done
[ ! -z $2 ] && cd ..