Last active
July 3, 2022 17:26
-
-
Save heywoodlh/092b51364326a423fdeeb9793adefd6c to your computer and use it in GitHub Desktop.
Youtube channel monitoring script
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 | |
# Script assumes the following: | |
# - streamlink is installed: `pip3 install streamlink` | |
# - gotify will be used to send push notifications (modify it yourself if you need another CLI push utility) | |
# Edit these variables | |
channel_id='' | |
channel_title='My Youtube Channel' | |
# This variable determines what command will be used to notify user | |
# ${notify_command} expects to receive stdin (i.e. `echo 'message' | ${notify_command}`) | |
notify_comand='gotify push' | |
# Testing link for lofi-beats channel (normally running all the time) | |
#streamlink "https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow/live" | |
# Testing link for MKBHD | |
#streamlink "https://www.youtube.com/c/mkbhd/live" | |
# Check if channel is livestreaming | |
streamlink "https://www.youtube.com/channel/${channel_id}/live" > /dev/null | |
status_code="$?" | |
[[ ${status_code} == 0 ]] && stream_status="up" | |
[[ ${status_code} != 0 ]] && stream_status="down" | |
if grep -q 'livestream is up' /tmp/livestream.txt | |
then | |
stream_prev_state='up' | |
else | |
stream_prev_state='down' | |
fi | |
[[ ${stream_prev_state} != ${stream_status} ]] && echo -n "${channel_title} livestream is ${stream_status}" | ${notify_comand} | |
[[ ${stream_status} == 'up' ]] && echo "${channel_title} livestream is up" | tee /tmp/livestream.txt | |
[[ ${stream_status} == 'down' ]] && echo "${channel_title} livestream is down" | tee /tmp/livestream.txt | |
## Don't exit with error code if the livestream is up | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment