/onemanga.sh

http://gsbabil.googlecode.com/ · Shell · 75 lines · 49 code · 16 blank · 10 comment · 5 complexity · 8f64b31ee86d582c384ea543428cb0a6 MD5 · raw file

  1. #!/bin/bash
  2. RED='\e[0;31m'
  3. CYAN='\e[0;36m'
  4. NC='\e[0m' # No Color
  5. if [ -z $1 ]
  6. then
  7. echo
  8. echo "[*] usage: `basename $0` manga_url"
  9. echo
  10. exit
  11. else
  12. manga_name=`echo $1 | awk -F '/' '{for(i=NF;i>=0;i--){if(length($i)>0){print $i;break;}}}'`
  13. fi
  14. main_url="http://www.onemanga.com"
  15. rm -rf ${manga_name}
  16. ##finding list of chapters
  17. echo -n -e "${CYAN}[*]${RED} Finding total chapters in ${CYAN} $manga_name ${NC}= "
  18. wget -q -nv ${main_url}/${manga_name} -O tmp.txt
  19. chapters=`cat tmp.txt | grep '<td class="ch-subject"><a href="/' | awk -F '"' '{print $4}'`
  20. count=0
  21. for c in $chapters
  22. do
  23. mkdir -p ./$c
  24. count=$((count+1))
  25. done
  26. echo -e "${CYAN}${count}${NC}"
  27. ##
  28. ##parse chapter and download
  29. for chapter in $chapters
  30. do
  31. pwd=`pwd`
  32. cd ./$chapter
  33. ## initial wget
  34. echo -e "${CYAN}[*]${RED} Trying to find the image base url${NC}"
  35. ## find collect the first page in the chapter
  36. wget -q -nv $main_url/$chapter -O tmp.txt
  37. page=`cat tmp.txt | grep "Begin reading" | awk -F '"' '{print $2}'`
  38. ## now go to that page & find image base
  39. wget -q -nv ${main_url}${page} -O tmp.txt 2>/dev/null
  40. image=`cat tmp.txt | grep "img_url" | awk -F '"' '{for(i=1;i<NF;i++){if($i ~ "jpg"){print $i}}}' | awk -F '/' '{print $NF}'`
  41. image_base=`cat tmp.txt | grep "img_url" | awk -F '"' '{for(i=1;i<NF;i++){if($i ~ "jpg"){print $i}}}' | sed s/"$image"//g`
  42. echo -e "${RED}>>${NC} $image_base"
  43. ## download
  44. d=$((d+1))
  45. names=`cat tmp.txt | awk '{for(i=1;i<=NF;i++){if($i ~ "selected")go++}{if(go>1){print}}}' | grep -e "</option>" -e 'credits</option>' -e 'extra*</option>' -e 'cover*</option>' | awk -F '"' '{print $2}'`
  46. n=0
  47. for k in $names
  48. do
  49. n=$((n+1))
  50. done
  51. echo -e "${CYAN}[*]${RED} Downloading ${CYAN}$n ${RED}images from chapter ${CYAN}$chapter ${RED} ... ##${CYAN}$((count-d+1))${RED}##${CYAN}$count${RED}##${NC}"
  52. for k in $names
  53. do
  54. #echo -e "${RED}>>${NC} ${image_base}${k}.jpg"
  55. wget -nv "${image_base}${k}.jpg"
  56. done
  57. cd $pwd
  58. done
  59. ##