Last active
November 5, 2025 23:59
-
-
Save jotson/a46cb412704aa8852ae70535201565e3 to your computer and use it in GitHub Desktop.
bash script that uses the twitch CLI to scan for a specific game being streamed
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 | |
| # Monitor twitch streams for specific games and alert when someone is playing | |
| # Get game_id: twitch api get games -q name="The Mailroom" | |
| # You can pass in multiple game_ids by adding the game_id param multiple times | |
| # Twitch CLI https://dev.twitch.tv/docs/cli/ | |
| # The Mailroom = 1216417455 | |
| LOG="log.txt" | |
| echo "Waiting for live streams..." | |
| while true; do | |
| OUTPUT=$(twitch api get streams -q game_id=1216417455 2>&1) | |
| if [[ "$OUTPUT" == *token* ]]; then | |
| echo "Refreshing token" | |
| twitch token refresh | |
| sleep 3 | |
| continue | |
| fi | |
| DATA=$(echo $OUTPUT | jq '.data | length') | |
| if [[ "$DATA" != "0" ]]; then | |
| TITLE=$(echo $OUTPUT | jq -r '.data[0].title') | |
| LOGIN=$(echo $OUTPUT | jq -r '.data[0].user_login') | |
| URL="https://twitch.tv/$LOGIN" | |
| MESSAGE="Twitch Live Stream $LOGIN: $TITLE" | |
| LOGMESSAGE="$(date --iso-8601) @$LOGIN $URL" | |
| grep "$LOGMESSAGE" "$LOG" >/dev/null | |
| if [ $? -ne 0 ]; then | |
| echo "$MESSAGE" | |
| echo "$LOGMESSAGE" >>"$LOG" | |
| fi | |
| fi | |
| sleep 120 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment