drpanwe icon

vimmvault script

drpanwe | PRO | 10/05/20 10:48:42 AM UTC | 0 ⭐ | 384 👁️ | Never ⏰ | []
Bash |

3.28 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
# Author: [email protected]
 
if [ $# -eq 0 ]; then
  echo "No arguments supplied. Example: ./script.sh https://vimm.net/vault/GB"
  exit 1
fi
 
arg="$1"
console=$(echo "$arg" | awk -F '/' '{print $(NF)}')
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
 
  # Construct letterpage
  if [ "$letter" = "#" ]; then
    letterpage="https://vimm.net/vault/?p=list&action=settings&section=%23&system=$console&v_us=1"
  else
    letterpage="https://vimm.net/vault/?p=list&action=settings&section=$letter&system=$console&v_us=1"
  fi
  echo "$letterpage"
  echo "======================="
 
  # Base URL (should be without trailing slash)
  baseURL="https://vimm.net"
 
  # find all gamepages in a letterpage
  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
    # Construct the gamepage URL
    gamepage="$baseURL$gamepage"
 
    skipit=false
    retries=0
 
    # Find the mediaID
    while true; do
      id=$(curl -s "$gamepage" | grep 'fileSize\[' | head -n 1 | cut -d \[ -f2 | cut -d \] -f1)
      if [ -z "$id" ]; then
        echo "\$id is empty. Retrying ...$retries"
        ((retries = retries + 1))
        if [[ "$retries" -gt 10 ]]; then
          skipit=true
          retries=0
          break
        fi
      else
        echo "\$id is $id"
        break
      fi
    done
 
    if [ "$skipit" = true ]; then
      echo 'Giving up on this one...'
      continue
    fi
 
    # Construct URL
    URL="https://download.vimm.net/download/?mediaId=$id"
 
    echo "Visiting $URL"
 
    # Check there is 404, so skip it
    skipit=false
    retries=0
 
    # Find the filename
    while true; do
      filename=$(curl -s -D - \
        -H "Referer: https://vimm.net/" \
        -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" \
        "$URL" | grep "Content-Disposition" | awk -F '=' '{print substr($2,2,length($2)-3)}')
      if [ -z "$filename" ]; then
        echo "\$filename is empty. Retrying ... $retries"
        ((retries = retries + 1))
        if [[ "$retries" -gt 10 ]]; then
          skipit=true
          retries=0
          break
        fi
      else
        echo "\$filename is $filename"
        break
      fi
    done
 
    if [ "$skipit" = true ]; then
      echo 'Giving up on this one...'
      continue
    fi
 
    # Download it
    while true; do
      curl -s \
        -H "Referer: https://vimm.net/" \
        -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" \
        "$URL" --output "$filename"
 
      # Test the file
      if test -f "$filename"; then
        echo "$filename has been downloaded"
        # Check if thefile is zip
        if file "$filename" | grep 'Zip archive data\|7-zip archive data' &>/dev/null; then
          echo "$filename is a valid Zip archive"
          break
        else
          echo "$filename is not a Zip archive. Retrying ..."
        fi
      else
        echo "$filename has not been downloaded. Retrying ..."
      fi
    done
    echo "---"
  done
 
done
 

Comments