drpanwe icon

snes_rom_downloader

drpanwe | PRO | 10/02/20 04:41:15 PM UTC | 0 ⭐ | 371 👁️ | Never ⏰ | []
Bash |

2.34 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
 
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&system=SNES&section=number"
  else
    letterpage="https://vimm.net/vault/SNES/$letter"
  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 'onmouseover="buildTooltip' |
    awk -F 'href="' '{print $2}' |
    cut -d '"' -f1); do
    # Construct the gamepage URL
    gamepage="$baseURL$gamepage"
 
    # 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 ..."
      else
        echo "\$id is $id"
        break
      fi
    done
 
    # Construct URL
    URL="https://download.vimm.net/download/?mediaId=$id"
    echo "Visiting $URL"
 
    # 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 ..."
      else
        echo "\$filename is $filename"
        break
      fi
    done
 
    # 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' &>/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