59 lines
1.7 KiB
Bash
Executable File
59 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
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
|
|
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
|
|
echo "You must enter a valid system name."
|
|
echo "Supported systemas are:"
|
|
for WORD in $SYSTEMS
|
|
do
|
|
echo -e "\t$WORD"
|
|
done
|
|
exit 0
|
|
fi
|
|
|
|
|
|
|
|
#check if file exists
|
|
if ! test -f "$1"; then
|
|
echo "$1 does not exists."
|
|
exit 0
|
|
fi
|
|
|
|
#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"
|
|
|
|
#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."
|
|
|
|
#create system folder for webpages with hashes
|
|
if test -d "./${GAME_LIST_DIR}/$SYSTEM_NAME"; then
|
|
rm -rdf "./${GAME_LIST_DIR}/$SYSTEM_NAME"
|
|
echo "Deleting ${GAME_LIST_DIR}/$SYSTEM_NAME folder."
|
|
fi
|
|
if ! test -d "./${GAME_LIST_DIR}/$SYSTEM_NAME"; then
|
|
mkdir -p "./${GAME_LIST_DIR}/$SYSTEM_NAME"
|
|
echo "Create ${GAME_LIST_DIR}/$SYSTEM_NAME folder."
|
|
fi
|
|
|
|
#download webpages with hashes form url list
|
|
echo "Downloading game info ..."
|
|
wget --random-wait --no-verbose --load-COOKIE_FILEs "${COOKIE_FILE}" -i "${URL_LIST}" -P "./${GAME_LIST_DIR}/${SYSTEM_NAME}"
|
|
|
|
#remove tempfiles
|
|
if test -f "$URL_LIST"; then
|
|
rm "$URL_LIST"
|
|
fi
|