dotfiles

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

stream-check.sh (1985B)


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