Huntereb

Madokami Auto-Downloader

May 27th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.57 KB | None | 0 0
  1. #Madokami auto-downloader by Huntereb
  2. #Simply fill in the variables at the top with your information
  3. #Use cron or some kind of scheduler to automate the downloading of files
  4.  
  5. #Directory to put our mangas
  6. dlDir="/home/user/downloads/manga"
  7. #Username for madokami
  8. userN="Username"
  9. #Password for madokami
  10. passW="Password"
  11. #The root directory for each manga you want to download (separate multiple with spaces)
  12. ourMangu=(https://manga.madokami.com/Manga/mangu1 https://manga.madokami.com/Manga/mangu2)
  13.  
  14. #---------------------------------------------------------------------------Don't edit anything below here!
  15.  
  16. urldecode() {
  17.     local url_encoded="${1//+/ }"
  18.     printf '%b' "${url_encoded//%/\\x}"
  19. }
  20.  
  21. RED='\033[0;31m'
  22. NC='\033[0m'
  23. ourDomain="https://manga.madokami.com"
  24.  
  25. if [ ! -d "$dlDir" ]; then
  26.     echo -e ""$RED"The directory \""$dlDir"\" does not exist; exiting.$NC"
  27.     exit 0
  28. fi
  29.  
  30. if [ ! "$userN" ] || [ ! "$passW" ]; then
  31.     echo -e ""$RED"A username and password is required to access Madokami; exiting.$NC"
  32.     exit 0
  33. fi
  34.  
  35. for currentMangu in "${ourMangu[@]}"
  36.     do
  37.         IFS=$'\n'
  38.        
  39.         wget -l 0 --user $userN --password $passW $currentMangu -O "$dlDir"/current
  40.         if [ $? -gt 0 ]; then
  41.              echo -e "$RED"$currentMangu" is not a valid Manga, or you entered an invalid username/password; skipping.$NC"
  42.              rm "$dlDir"/current
  43.              continue
  44.         fi
  45.  
  46.         foundTitles=($(grep --null "rel=\"nofollow\">" "$dlDir"/current))
  47.         ourName=($(grep --null "class=\"title\"" "$dlDir"/current))
  48.         IFS=$'<>'
  49.        
  50.         if [ ! "$ourName" ]; then
  51.             IFS=$'/'
  52.             read -r -a ourName <<< "$currentMangu"
  53.             ourName=$(urldecode ${ourName[-1]})
  54.         else
  55.             read -r -a ourName <<< "$ourName"
  56.             ourName="${ourName[-2]}"
  57.         fi
  58.        
  59.         rm "$dlDir"/current
  60.  
  61.         if [ ! -d "$dlDir"/"$ourName" ]; then
  62.                 mkdir "$dlDir"/"$ourName"
  63.         fi
  64.  
  65.         for i in "${foundTitles[@]}"
  66.             do
  67.                 IFS=$'\"'
  68.                 read -r -a ourFile <<< "$i"
  69.                 IFS=$'<>'
  70.                 read -r -a ourLocalFile <<< "$i"
  71.                 IFS=$'.<'
  72.                 read -r -a ourLocalFileExt <<< "$i"
  73.                 IFS=$'\n'
  74.                 if [ "${ourLocalFileExt[-2]}" = "zip" ]; then
  75.                     ourLocalFile="${ourLocalFile[-2]::-3}cbz"
  76.                 elif [ "${ourLocalFileExt[-2]}" = "rar" ]; then
  77.                     ourLocalFile="${ourLocalFile[-2]::-3}cbr"
  78.                 else
  79.                     echo -e "$REDUnexpected file type; skipping.$NC"
  80.                     continue
  81.                 fi
  82.                 if [ ! -f "$dlDir"/"$ourName"/"$ourLocalFile" ]; then
  83.                     wget -l 0 --user $userN --password $passW "$ourDomain""${ourFile[1]}" -O ""$dlDir"/"$ourName"/"$ourLocalFile""
  84.                 else
  85.                     echo -e "$RED"$ourLocalFile" already exists; skipping.$NC"
  86.                 fi
  87.             done
  88.  
  89.     done
  90.  
  91. exit 0
Add Comment
Please, Sign In to add comment