2025-01-03 22:00:13 +00:00
|
|
|
#!/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"
|
2025-03-28 21:18:52 +00:00
|
|
|
echo "Invalid url: $i"
|
|
|
|
exit
|
2025-01-03 22:00:13 +00:00
|
|
|
end
|
2025-03-28 21:18:52 +00:00
|
|
|
if test (echo $page | pup title text{}) = "Just a moment..."
|
2025-01-03 22:00:13 +00:00
|
|
|
open $i
|
|
|
|
echo "Solve captcha in browser, then press enter."
|
|
|
|
read
|
2025-03-28 21:18:52 +00:00
|
|
|
sleep 5
|
|
|
|
continue
|
2025-01-03 22:00:13 +00:00
|
|
|
end
|
2025-03-28 21:18:52 +00:00
|
|
|
break
|
2025-01-03 22:00:13 +00:00
|
|
|
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"
|