drpanwe

vimmvault script

Oct 5th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.28 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $# -eq 0 ]; then
  4.   echo "No arguments supplied. Example: ./script.sh https://vimm.net/vault/GB"
  5.   exit 1
  6. fi
  7.  
  8. arg="$1"
  9. console=$(echo "$arg" | awk -F '/' '{print $(NF)}')
  10. for letter in \# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do
  11.  
  12.   # Construct letterpage
  13.   if [ "$letter" = "#" ]; then
  14.     letterpage="https://vimm.net/vault/?p=list&action=settings&section=%23&system=$console&v_us=1"
  15.   else
  16.     letterpage="https://vimm.net/vault/?p=list&action=settings&section=$letter&system=$console&v_us=1"
  17.   fi
  18.   echo "$letterpage"
  19.   echo "======================="
  20.  
  21.   # Base URL (should be without trailing slash)
  22.   baseURL="https://vimm.net"
  23.  
  24.   # find all gamepages in a letterpage
  25.   for gamepage in $(curl -s "$letterpage" | grep 'a href="\/vault' | awk -F 'href="' '{print $2}' | cut -d '"' -f1 | grep -v '?p=' | grep -v "vault/NES\|vault/$console"); do
  26.     # Construct the gamepage URL
  27.     gamepage="$baseURL$gamepage"
  28.  
  29.     skipit=false
  30.     retries=0
  31.  
  32.     # Find the mediaID
  33.     while true; do
  34.       id=$(curl -s "$gamepage" | grep 'fileSize\[' | head -n 1 | cut -d \[ -f2 | cut -d \] -f1)
  35.       if [ -z "$id" ]; then
  36.         echo "\$id is empty. Retrying ...$retries"
  37.         ((retries = retries + 1))
  38.         if [[ "$retries" -gt 10 ]]; then
  39.           skipit=true
  40.           retries=0
  41.           break
  42.         fi
  43.       else
  44.         echo "\$id is $id"
  45.         break
  46.       fi
  47.     done
  48.  
  49.     if [ "$skipit" = true ]; then
  50.       echo 'Giving up on this one...'
  51.       continue
  52.     fi
  53.  
  54.     # Construct URL
  55.     URL="https://download.vimm.net/download/?mediaId=$id"
  56.  
  57.     echo "Visiting $URL"
  58.  
  59.     # Check there is 404, so skip it
  60.     skipit=false
  61.     retries=0
  62.  
  63.     # Find the filename
  64.     while true; do
  65.       filename=$(curl -s -D - \
  66.         -H "Referer: https://vimm.net/" \
  67.         -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" \
  68.         "$URL" | grep "Content-Disposition" | awk -F '=' '{print substr($2,2,length($2)-3)}')
  69.       if [ -z "$filename" ]; then
  70.         echo "\$filename is empty. Retrying ... $retries"
  71.         ((retries = retries + 1))
  72.         if [[ "$retries" -gt 10 ]]; then
  73.           skipit=true
  74.           retries=0
  75.           break
  76.         fi
  77.       else
  78.         echo "\$filename is $filename"
  79.         break
  80.       fi
  81.     done
  82.  
  83.     if [ "$skipit" = true ]; then
  84.       echo 'Giving up on this one...'
  85.       continue
  86.     fi
  87.  
  88.     # Download it
  89.     while true; do
  90.       curl -s \
  91.         -H "Referer: https://vimm.net/" \
  92.         -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" \
  93.         "$URL" --output "$filename"
  94.  
  95.       # Test the file
  96.       if test -f "$filename"; then
  97.         echo "$filename has been downloaded"
  98.         # Check if thefile is zip
  99.         if file "$filename" | grep 'Zip archive data\|7-zip archive data' &>/dev/null; then
  100.           echo "$filename is a valid Zip archive"
  101.           break
  102.         else
  103.           echo "$filename is not a Zip archive. Retrying ..."
  104.         fi
  105.       else
  106.         echo "$filename has not been downloaded. Retrying ..."
  107.       fi
  108.     done
  109.     echo "---"
  110.   done
  111.  
  112. done
  113.  
Add Comment
Please, Sign In to add comment