Created
November 27, 2016 19:46
-
-
Save SonoSooS/ab811365954f4df80c6b67020abe27e7 to your computer and use it in GitHub Desktop.
kagiya-ctr checker and notifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# =================================== | |
# kagiya-ctr checker bash script | |
# | |
# created by MarcusD | |
# Copyright $(date +"%Y") | |
# | |
# :P | |
# =================================== | |
function get_raw { | |
curl -k -D - -o /dev/null "https://kagiya-ctr.cdn.nintendo.net/title/0x$1/ext_key?country=$2" 2>/dev/null | |
} | |
function sendnotif { | |
notify-send -t 30000 -i firefox "kagiya-ctr" "$1" | |
} | |
function testerr { | |
grep "HTTP/....$1" 2>&1 >/dev/null | |
} | |
# ========================== # | |
# ===== [ BEGIN HERE ] ===== # | |
# ========================== # | |
COMD='' | |
case "$1" in | |
add) | |
echo "$3,$4,$2" >>~/.kagiya | |
exit 0 | |
;; | |
delall) | |
rm ~/.kagiya | |
exit 0 | |
;; | |
list) | |
while IFS=, read -r tid reg name | |
do | |
echo "$name ($tid $reg)" | |
done < ~/.kagiya | |
exit 0 | |
;; | |
loop) | |
COMD="$2" | |
;; | |
cleanup) | |
DUMMY=$(cat ~/.kagiya) | |
while IFS=, read -r tid reg name | |
do | |
if get_raw $tid $reg | testerr 200; then | |
echo "Removing $name ($tid $reg) because it came out" | |
DUMMY=$(echo "$DUMMY" | grep -v "$tid,$reg,$name") | |
fi | |
done < ~/.kagiya | |
echo "$DUMMY" >~/.kagiya | |
exit 0 | |
;; | |
*) | |
echo "Invalid command: '$1'" | |
echo "Usage:" | |
echo "- $0 add <gamename> <TID16> <region2>" | |
echo " - adds a game to the checklist" | |
echo "- $0 list" | |
echo " - lists all games" | |
echo "- $0 delall" | |
echo " - resets the checklist" | |
echo "- $0 cleanup" | |
echo " - removes all released games" | |
echo "- $0 loop [timeout]" | |
echo " - check stuff and loop in [timeout] intervals if [timeout] is present" | |
exit 1 | |
;; | |
esac | |
while : ; do | |
while IFS=, read -r tid reg name | |
do | |
if get_raw $tid $reg | testerr 200; then | |
sendnotif "$name came out!" | |
fi | |
done < ~/.kagiya | |
[ "x$COMD" == "x" ] && break | |
sleep $COMD | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment