Last active
December 16, 2021 07:00
-
-
Save flexiondotorg/f6deafa4313c1f7d8a30f9da6c57b760 to your computer and use it in GitHub Desktop.
Get Twitch channel metrics via DecAPI
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
#!/usr/bin/env bash | |
TWITCH_CHANNEL="wimpysworld" | |
METRICS_PATH="${HOME}/Studio/OBS/twitch-metrics" | |
mkdir -p "${METRICS_PATH}" | |
for ENDPOINT in $(wget -q https://decapi.net/twitch/ -O - | jq -r '[.endpoints[] | select(contains("CHANNEL")) | select(contains("USER") | not)] | @tsv'); do | |
ENDPOINT_NAME=$(echo "${ENDPOINT}" | cut -d'/' -f5) | |
ENDPOINT_URL="${ENDPOINT//\{CHANNEL\}/${TWITCH_CHANNEL}}" | |
# Get the 5 most recent followers and skip deprecated endpoints. | |
if [ "${ENDPOINT_NAME}" == "followers" ]; then | |
ENDPOINT_URL+="?count=5" | |
elif [[ "${ENDPOINT_NAME}" == *hosts* ]]; then | |
echo " - Deprecated; skipping it." | |
continue | |
fi | |
echo " - Getting ${ENDPOINT_URL}" | |
DATA=$(wget -q "${ENDPOINT_URL}" -O-) | |
# If the channel is offline, report zero viewers | |
if [ "${ENDPOINT_NAME}" == "viewercount" ] && [[ "${DATA}" == *offline* ]]; then | |
DATA="0" | |
fi | |
echo -n "${DATA}" > "${METRICS_PATH}/${ENDPOINT_NAME}.txt" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment