dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

stream-check.sh (1811B)


      1 #!/bin/sh
      2 
      3 CONFIG_FILE="$XDG_CONFIG_HOME/regexghost/streams.csv"
      4 
      5 format="pretty"
      6 [ "$1" = "-yn" ] && format="yn" && shift
      7 
      8 line="$(grep "^${1}," "$CONFIG_FILE")"
      9 [ "$line" = "" ] && exit
     10 
     11 name="$(echo "$line" | cut -d "," -f 1)"
     12 twitch_at="$(echo "$line" | cut -d "," -f 2)"
     13 youtube_at="$(echo "$line" | cut -d "," -f 3)"
     14 kick_at="$(echo "$line" | cut -d "," -f 4)"
     15 
     16 if ! [ "$twitch_at" = "NONE" ]; then
     17 	curl --connect-timeout 5 -s "https://www.twitch.tv/${twitch_at}" > /tmp/live_twitch.html
     18 	if grep -q "live_user" /tmp/live_twitch.html; then
     19 		if [ "$format" = "pretty" ]; then
     20 			echo "${name} is live on Twitch: https://www.twitch.tv/${twitch_at}"
     21 		elif [ "$format" = "yn" ]; then
     22 			echo "y"
     23 			exit
     24 		fi
     25 	fi
     26 fi
     27 if ! [ "$youtube_at" = "NONE" ]; then
     28 	curl --connect-timeout 5 -s "https://www.youtube.com/${youtube_at}/live" > /tmp/live_youtube.html
     29 	if grep -q "isUpcoming\":true" /tmp/live_youtube.html; then
     30 		if [ "$format" = "pretty" ]; then
     31 			echo "${name} is about to go live on YouTube: https://www.youtube.com/${youtube_at}/live"
     32 		elif [ "$format" = "yn" ]; then
     33 			echo "w"
     34 			exit
     35 		fi
     36 	elif grep -q "isLive\":true" /tmp/live_youtube.html; then
     37 		if [ "$format" = "pretty" ]; then
     38 			echo "${name} is live on YouTube: https://www.youtube.com/${youtube_at}/live"
     39 		elif [ "$format" = "yn" ]; then
     40 			echo "y"
     41 			exit
     42 		fi
     43 	fi
     44 fi
     45 if ! [ "$kick_at" = "NONE" ]; then
     46 	wget --hsts-file="$XDG_STATE_HOME/wget-hsts" --timeout=5 -q --user-agent "NetSurf" "https://kick.com/api/v1/channels/${kick_at}" -O /tmp/live_kick.html
     47 	if grep -q "is_live\":true" /tmp/live_kick.html; then
     48 		if [ "$format" = "pretty" ]; then
     49 			echo "${name} is live on Kick: https://www.kick.com/${kick_at}"
     50 		elif [ "$format" = "yn" ]; then
     51 			echo "y"
     52 			exit
     53 		fi
     54 	fi
     55 fi
     56 
     57 if [ "$format" = "yn" ]; then
     58 	echo "n"
     59 	exit
     60 fi