Advertisement
mosaid

get-novel.sh

Feb 29th, 2020
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.20 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.  
  10. cd "${HOME}/articls/manga/get-novel"
  11. novel="$1"
  12. chapter="$2"
  13. [[ -z "$chapter" ]] && chapter=1
  14.  
  15. if ! [[ -d "$novel" ]] ; then
  16.     mkdir "$novel"
  17. fi
  18.  
  19. function CURL (){
  20.     userAgent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:48.0) "
  21.     userAgent+="Gecko/20100101 Firefox/48.0"
  22.     curl -s -A "$userAgent" "$@"
  23. }
  24.  
  25. chapter=$((chapter-1))
  26. while true ; do
  27.     chapter=$((chapter+1))
  28.     if [[ -f "$novel/chapter_$chapter.txt" ]]
  29.         then continue
  30.     fi
  31.     echo "getting chapter $chapter"
  32.     echo -en "\e[1A"
  33.     data=$(
  34.         CURL "https://bestlightnovel.com/novel_$novel/chapter_$chapter"|
  35.         sed -n '/<div id="vung_doc" class="vung_doc">/,/<\/div>/p' |
  36.         sed 's/<div id="vung_doc" class="vung_doc">//' |
  37.         sed 's/<p>/\n\n/g'|sed 's/<[^>]*>//g'|fmt -w 75
  38.     )
  39.     if (( ${#data} <= 5 )) ; then
  40.         echo
  41.         echo "no data."
  42.         exit
  43.     fi
  44.     echo "$data" > "$novel/chapter_$chapter.txt"
  45.     sleep 7
  46. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement