From eae737a216c79d2696e8e31de9487de783523fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Fri, 18 Dec 2020 21:43:28 +0100 Subject: [PATCH] Merged script 1 and script 2 --- 2_download_system_game_webpages.sh | 179 +++++++++++++++++++++++++---- 1 file changed, 158 insertions(+), 21 deletions(-) diff --git a/2_download_system_game_webpages.sh b/2_download_system_game_webpages.sh index fdcbe68..3d06f43 100755 --- a/2_download_system_game_webpages.sh +++ b/2_download_system_game_webpages.sh @@ -1,42 +1,179 @@ #!/bin/bash + +readonly USAGE=" +USAGE: +$(basename "$0") [SYSTEM]" + +function help_message() { + echo "$USAGE" + echo + echo "Where [SYSTEM] are:" + for WORD in $SYSTEMS; do + echo -e "\t$WORD" + done +} + SYSTEMS="apple2 arcade atari2600 atari7800 atarilynx coleco gamegear gb gba gbc mastersystem megadrive msx n64 nes ngpc pcengine sega32x sg1000 snes vectrex virtualboy wonderswan wonderswancolor" -#check if there is any parameter +# check if there is any parameter if [ "$#" -ne 1 ]; then echo "You must enter a system name." exit 0 fi # check if the parameter is valid -if ! echo "$SYSTEMS" | grep -w "$1" > /dev/null; then +if ! echo "$SYSTEMS" | grep -w "$1" >/dev/null; then echo "You must enter a valid system name." - echo "Supported systemas are:" - for WORD in $SYSTEMS - do - echo -e "\t$WORD" - done + help_message exit 0 fi - - -#check if file exists -if ! test -f "$1"; then - echo "$1 does not exists." - exit 0 -fi - -#variables +# variables readonly SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" readonly GAME_LIST_DIR="$SCRIPT_DIR/gamelists" -SYSTEM_NAME="$1" -URL_LIST="$SCRIPT_DIR/${SYSTEM_NAME}.url" -COOKIE_FILE="$SCRIPT_DIR/cookie.txt" +readonly SYSTEM_NAME="$1" +readonly SYSTEM_HTML="GAME_LIST_DIR/$SYSTEM_NAME".html +readonly URL_LIST="$SCRIPT_DIR/${SYSTEM_NAME}.url" +readonly COOKIE_FILE="$SCRIPT_DIR/cookie.txt" + +case $SYSTEM_NAME in + +apple2) + readonly URL="https://retroachievements.org/gameList.php?c=38" + ;; + +arcade) + readonly URL="https://retroachievements.org/gameList.php?c=27" + ;; + +atari2600) + readonly URL="https://retroachievements.org/gameList.php?c=25" + ;; + +atari7800) + readonly URL="https://retroachievements.org/gameList.php?c=51" + ;; + +atarijaguar) + readonly URL="https://retroachievements.org/gameList.php?c=17" + ;; + +atarilynx) + readonly URL="https://retroachievements.org/gameList.php?c=13" + ;; + +coleco) + readonly URL="https://retroachievements.org/gameList.php?c=44" + ;; + +gba) + readonly URL="https://retroachievements.org/gameList.php?c=5" + ;; + +gbc) + readonly URL="https://retroachievements.org/gameList.php?c=6" + ;; + +gb) + readonly URL="https://retroachievements.org/gameList.php?c=4" + ;; + +gamegear) + readonly URL="https://retroachievements.org/gameList.php?c=15" + ;; + +mastersystem) + readonly URL="https://retroachievements.org/gameList.php?c=11" + ;; + +megadrive) + readonly URL="https://retroachievements.org/gameList.php?c=1" + ;; + +msx) + readonly URL="https://retroachievements.org/gameList.php?c=29" + ;; + +ngpc) + readonly URL="https://retroachievements.org/gameList.php?c=14" + ;; + +nes) + readonly URL="https://retroachievements.org/gameList.php?c=7" + ;; + +n64) + readonly URL="https://retroachievements.org/gameList.php?c=2" + ;; + +nds) + readonly URL="https://retroachievements.org/gameList.php?c=18" + ;; + +panasonic3do) + readonly URL="https://retroachievements.org/gameList.php?c=43" + ;; + +pc8000) + readonly URL="https://retroachievements.org/gameList.php?c=47" + ;; + +pcengine) + readonly URL="https://retroachievements.org/gameList.php?c=8" + ;; + +pcfx) + readonly URL="https://retroachievements.org/gameList.php?c=49" + ;; + +psx) + readonly URL="https://retroachievements.org/gameList.php?c=12" + ;; + +pokemonmini) + readonly URL="https://retroachievements.org/gameList.php?c=24" + ;; + +sega32x) + readonly URL="https://retroachievements.org/gameList.php?c=10" + ;; + +segacd) + readonly URL="https://retroachievements.org/gameList.php?c=9" + ;; + +segasaturn) + readonly URL="https://retroachievements.org/gameList.php?c=39" + ;; + +sg1000) + readonly URL="https://retroachievements.org/gameList.php?c=33" + ;; + +snes) + readonly URL="https://retroachievements.org/gameList.php?c=3" + ;; + +vectrex) + readonly URL="https://retroachievements.org/gameList.php?c=46" + ;; + +virtualboy) + readonly URL="https://retroachievements.org/gameList.php?c=28" + ;; + +wonderswan) + readonly URL="https://retroachievements.org/gameList.php?c=53" + ;; + +esac + +wget "$URL" -O "$SYSTEM_HTML" #process system html to get game url list echo "Processing $SYSTEM_NAME." -grep -E "Game/[0-9]+" -Eo "$1" | sort -u | sed 's,Game/,https://retroachievements.org/linkedhashes.php?g=,' "$URL_LIST" -echo "Found $(wc -l < "$URL_LIST") games." +grep -E "Game/[0-9]+" -Eo "$SYSTEM_HTML" | sort -u | sed 's,Game/,https://retroachievements.org/linkedhashes.php?g=,' "$URL_LIST" +echo "Found $(wc -l <"$URL_LIST") games." #create system folder for webpages with hashes if test -d "./${GAME_LIST_DIR}/$SYSTEM_NAME"; then