1
0
Fork 0
mirror of https://github.com/Phantop/dotfiles synced 2025-08-30 02:14:55 +00:00
dotfiles/bin/shub

39 lines
1.1 KiB
Fish
Executable file

#!/usr/bin/fish
set url $argv[1]
set base (qtcurl $url)
set author (echo $base | pup .auth_name_fic text{})
set chaps (echo $base | pup .toc_a attr{href})
set cover (echo $base | pup .fic_image img attr{src})
set title (echo $base | pup .fic_title text{})
set dir $author - $title
mkdir -- "$dir"
for i in $chaps
while true
set page (qtcurl $i)
if test -z "$page"
echo "Invalid url: $i"
exit
end
if test (echo $page | pup title text{}) = "Just a moment..."
open $i
echo "Solve captcha in browser, then press enter."
read
sleep 5
continue
end
break
end
set num (echo $i | rev | cut -d/ -f2 | rev)
set ch_title (echo $page | pup title text{})
set h1_title "<h1>$ch_title</h1>"
echo $h1_title (echo $page | pup .chp_raw) > "$dir/$num. $ch_title.html"
end
wget $cover -O "$dir/cover"
pandoc --metadata title="$title" --metadata author="$author" --epub-cover-image="$dir/cover" "$dir"/*.html -o "$dir.epub"
rm -r -- "$dir"