drpanwe

vimmvault script

Oct 5th, 2020
96
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. # Author: drpaneas@gmail.com
  3.  
  4. if [ $# -eq 0 ]; then
  5.   echo "No arguments supplied. Example: ./script.sh https://vimm.net/vault/GB"
  6.   exit 1
  7. fi
  8.  
  9. arg="$1"
  10. console=$(echo "$arg" | awk -F '/' '{print $(NF)}')
  11. 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
  12.  
  13.   # Construct letterpage
  14.   if [ "$letter" = "#" ]; then
  15.     letterpage="https://vimm.net/vault/?p=list&action=settings&section=%23&system=$console&v_us=1"
  16.   else
  17.     letterpage="https://vimm.net/vault/?p=list&action=settings&section=$letter&system=$console&v_us=1"
  18.   fi
  19.   echo "$letterpage"
  20.   echo "======================="
  21.  
  22.   # Base URL (should be without trailing slash)
  23.   baseURL="https://vimm.net"
  24.  
  25.   # find all gamepages in a letterpage
  26.   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
  27.     # Construct the gamepage URL
  28.     gamepage="$baseURL$gamepage"
  29.  
  30.     skipit=false
  31.     retries=0
  32.  
  33.     # Find the mediaID
  34.     while true; do
  35.       id=$(curl -s "$gamepage" | grep 'fileSize\[' | head -n 1 | cut -d \[ -f2 | cut -d \] -f1)
  36.       if [ -z "$id" ]; then
  37.         echo "\$id is empty. Retrying ...$retries"
  38.         ((retries = retries + 1))
  39.         if [[ "$retries" -gt 10 ]]; then
  40.           skipit=true
  41.           retries=0
  42.           break
  43.         fi
  44.       else
  45.         echo "\$id is $id"
  46.         break
  47.       fi
  48.     done
  49.  
  50.     if [ "$skipit" = true ]; then
  51.       echo 'Giving up on this one...'
  52.       continue
  53.     fi
  54.  
  55.     # Construct URL
  56.     URL="https://download.vimm.net/download/?mediaId=$id"
  57.  
  58.     echo "Visiting $URL"
  59.  
  60.     # Check there is 404, so skip it
  61.     skipit=false
  62.     retries=0
  63.  
  64.     # Find the filename
  65.     while true; do
  66.       filename=$(curl -s -D - \
  67.         -H "Referer: https://vimm.net/" \
  68.         -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" \
  69.         "$URL" | grep "Content-Disposition" | awk -F '=' '{print substr($2,2,length($2)-3)}')
  70.       if [ -z "$filename" ]; then
  71.         echo "\$filename is empty. Retrying ... $retries"
  72.         ((retries = retries + 1))
  73.         if [[ "$retries" -gt 10 ]]; then
  74.           skipit=true
  75.           retries=0
  76.           break
  77.         fi
  78.       else
  79.         echo "\$filename is $filename"
  80.         break
  81.       fi
  82.     done
  83.  
  84.     if [ "$skipit" = true ]; then
  85.       echo 'Giving up on this one...'
  86.       continue
  87.     fi
  88.  
  89.     # Download it
  90.     while true; do
  91.       curl -s \
  92.         -H "Referer: https://vimm.net/" \
  93.         -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" \
  94.         "$URL" --output "$filename"
  95.  
  96.       # Test the file
  97.       if test -f "$filename"; then
  98.         echo "$filename has been downloaded"
  99.         # Check if thefile is zip
  100.         if file "$filename" | grep 'Zip archive data\|7-zip archive data' &>/dev/null; then
  101.           echo "$filename is a valid Zip archive"
  102.           break
  103.         else
  104.           echo "$filename is not a Zip archive. Retrying ..."
  105.         fi
  106.       else
  107.         echo "$filename has not been downloaded. Retrying ..."
  108.       fi
  109.     done
  110.     echo "---"
  111.   done
  112.  
  113. done
  114.  
Add Comment
Please, Sign In to add comment