Advertisement
mosaid

get-novel.sh

Jan 26th, 2020
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.00 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # this script will download all available chapters
  4. # of the light novel starting from a given chapter
  5. # get the novel id from the website
  6. # example :  888141268 is the id of:
  7. # this hero is overpowred but overly cautious
  8. #
  9. novel="$1"
  10. chapter="$2"
  11. [[ -z "$chapter" ]] && chapter=1
  12.  
  13. if ! [[ -d "$novel" ]] ; then
  14.     mkdir "$novel"
  15. fi
  16.  
  17. function CURL (){
  18.     userAgent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:48.0) "
  19.     userAgent+="Gecko/20100101 Firefox/48.0"
  20.     curl -s -A "$userAgent" "$@"
  21. }
  22.  
  23. while true ; do
  24.     echo "getting chapter $chapter"
  25.     echo -en "\e[1A"
  26.     data=$(
  27.         CURL "https://bestlightnovel.com/novel_$novel/chapter_$chapter"|
  28.         sed -n '/<div id="vung_doc" class="vung_doc">/,/<\/div>/p' |
  29.         sed 's/<div id="vung_doc" class="vung_doc">//' |
  30.         sed 's/<p>/\n\n/g'|sed 's/<[^>]*>//g'|fmt -w 75
  31.     )
  32.     (( ${#data} <= 5 )) && exit
  33.     echo "$data" > "$novel/chapter_$chapter.txt"
  34.     chapter=$(($chapter+1))
  35.     sleep 7
  36. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement