Last active
December 9, 2018 23:31
-
-
Save micalevisk/b2bbf84335e1108553964146fcae3e4e to your computer and use it in GitHub Desktop.
Simple Shell Script to list all channels in which a Twitch TV (API v5) user is on chat
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 | |
# | |
# List all channels in which a Twitch TV user is on chat. | |
# | |
# USAGE: | |
# ./list_channels.sh <user_id> <username> | |
# | |
# Created by Micael Levi on 22/01/2018 | |
# Copyright (c) 2018 <[email protected]> All rights reserved | |
# | |
# using: mapfile, curl, jq, printf, rm, sleep | |
# | |
[ $# -ne 2 ] && { printf "%s <user_id> <username>\\n" "$0"; exit 1; } | |
declare -r CLIENT_ID="<YOUR-CLIENT-ID>" | |
declare -r LOADING_MARKER="(...)" | |
declare -i amount=0 | |
declare -r user_id="$1" username="$2" | |
## @see https://dev.twitch.tv/docs/v5/reference/users#get-user-follows | |
mapfile -t follows <<< "$(curl -s -H 'Accept: application/vnd.twitchtv.v5+json' -X GET "https://api.twitch.tv/kraken/users/${user_id,,}/follows/channels?client_id=${CLIENT_ID}" | jq --raw-output '.follows[].channel.name')" | |
[ -z "${follows[0]}" ] && { rm -f jq*.stackdump; exit 2; } | |
printf "'%s'\\x1B[s is online on channels:\\n" "$username" | |
for channel in "${follows[@]}" | |
do | |
printf "%s%s" "$channel" "$LOADING_MARKER" | |
isOnChat=$(curl -s "http://tmi.twitch.tv/group/user/${channel,,}/chatters" | jq --raw-output ".chatters | flatten | contains([\"${username,,}\"])") | |
[ "$isOnChat" == "true" ] && { printf "\\x1B[%dD\\x1B[K\\n" "${#LOADING_MARKER}" ; ((amount++)); } || printf "\\x1B[G\\x1B[K" | |
sleep 0.1 | |
done | |
[ "$amount" -eq 0 ] && printf "\\x1B[u isn't online on any channel (that his follows) \\x1B[K\\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update 2018-12-09 ~ version with auto-fetch
user_id
: