Skip to content

Instantly share code, notes, and snippets.

@raidzero
Created March 3, 2014 00:22
Show Gist options
  • Save raidzero/9316254 to your computer and use it in GitHub Desktop.
Save raidzero/9316254 to your computer and use it in GitHub Desktop.
Print game ID of wii/gamecube file and download game cover artwork
#!/bin/sh
# this script will print internal game name and ID to the screen for gamecube/wii games and download artwork
ARTWORK_DIR=~/storage/ROMs/artwork
function die()
{
rm /tmp/game{Name,ID,WBFS} &> /dev/null
echo $1
exit $2
}
FILE="$1"
ARTWORK="$2"
if [ -z "$FILE" ]; then
echo "USAGE: `basename $0` FILE.[wbfs/iso]"
exit 1
fi
if [ ! -f "$FILE" ]; then
die "File not found." 1
fi
isISO=`echo $FILE | grep -i "iso$"`
isWBFS=`echo $FILE | grep -i "wbfs$"`
if [ -z "$isISO" ] && [ -z "$isWBFS" ]; then
die "$FILE is not an ISO/WBFS file!" 1
fi
# ISO ID is the first 6 bytes, name starts at byte 32
# WBFS ID is 6 bytes starting at byte 512, name starts at byte 544
if [ -n "$isISO" ]; then
dd if="$FILE" of=/tmp/gameID count=6 bs=1 &> /dev/null
dd if="$FILE" of=/tmp/gameName skip=32 bs=1 count=100 &> /dev/null
elif [ -n "$isWBFS" ]; then
# check the file header
dd if="$FILE" of=/tmp/gameWBFS bs=1 count=4 &>/dev/null
HEADER=`cat /tmp/gameWBFS`
[ "$HEADER" != "WBFS" ] && die "Invalid WBFS file." 1
dd if="$FILE" of=/tmp/gameID skip=512 count=6 bs=1 &>/dev/null
dd if="$FILE" of=/tmp/gameName skip=544 bs=1 count=100 &>/dev/null
fi
ID=`cat /tmp/gameID`
REMOTEID=$ID
NAME=`cat /tmp/gameName`
if [ -z "$ID" ] && [ -z "$NAME" ]; then
die "Name/ID not found. Are you sure this is a Wii/Gamecube file?" 1
else
if [ -n "$ARTWORK" ]; then
# download the artwork from gametdb if we dont already have it
if [ ! -f "$ARTWORK_DIR/$ID.png" ]; then
REMOTEID=`echo $ID | sed -r 's/([A-Z0-9]{3})P([0-9A-Z]{2})/\1E\2/'` # I don't want PAL artwork
echo "Downloading artwork [$REMOTEID]..."
wget -O $ARTWORK_DIR/$ID.png --quiet http://art.gametdb.com/wii/cover3D/US/$REMOTEID.png
if [ $? -ne 0 ]; then
echo "Artwork download for $NAME [$REMOTEID] failed. NTSC ID cannot be translated to PAL ID"
rm $ARTWORK_DIR/$ID.png
fi
fi
fi
die "$NAME [$ID]" 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment