#scheduled stream tracker for youtube
#lists the live and scheduled streams from a list of channels
# upgraded: https://rentry.org/quicktrackyt

#required arguments: channels_file invidious_instance
#output is stored in out.txt, use grep and sort to filter accordingly
#sample run: sh trackstreamyt.sh sked_active.txt https://invidious.privacydev.net; grep ^Live out.txt; echo; grep "[[:digit:]] minute" out.txt | sort; echo; grep "[[:digit:]] hour" out.txt | sort; echo; grep "[[:digit:]] day" out.txt
#another sample run: sh trackstreamyt.sh sked_active.txt https://invidious.privacydev.net; echo; awk -F'+' 'BEGIN {print "LIVE NOW"} /^Live/ {printf("%s/%s\n%s%s%s\n",$2,$3,$4,$5,$6)}' out.txt | sed "s/^ //" | sed "s/^.* https/https/"; echo; awk -F'+' 'BEGIN {print "VERY SOON"} /^Premieres in [0-9]+ minute/ {printf("%s/%s/ %s\n%s%s%s\n",$2,$3,$1,$4,$5,$6)}' out.txt | sed "s/^ //" | sed "s/^.* https/https/"; echo; awk -F'+' 'BEGIN {print "SOON"} /^Premieres in [0-9] hour/ {printf("%s/%s/ %s\n%s%s%s\n",$2,$3,$1,$4,$5,$6)}' out.txt | sed "s/^ //" | sed "s/^.* https/https/"; echo; awk -F'+' 'BEGIN {print "LATER TODAY / EARLY TOMORROW"} /^Premieres in [0-9][0-9] hour/ {printf("%s/%s/ %s\n%s%s%s\n",$2,$3,$1,$4,$5,$6)}' out.txt | sed "s/^ //" | sed "s/^.* https/https/"; echo; awk -F'+' 'BEGIN {print "LATER THIS WEEK / NEXT WEEK"} /^Premieres in [0-9] day/ {printf("%s/%s/ %s\n%s%s%s\n",$2,$3,$1,$4,$5,$6)}' out.txt | sed "s/^ //" | sed "s/^.* https/https/";echo; echo DOUBLE CHECK YUME+; grep -i yume out.txt

#channels_file contains a list of channel ids
#sample content 
#UCqfVP-d0Flj_ygWJ9m8gHMQ
#UCIoRFfQdwgErIokdU4Zb-Sg
#UCejbicoRnQjCOdAPAv5JPwg
#last line is empty (hit enter on the last channel id or else it will not be read)

#tested with the following invidious instances
# https://vid.puffyan.us
# https://invidious.privacydev.net
#for other instances go to invidio.us
#check first if the url loads properly in the browser

#recommended run schedule is every 45th minute of the hour
#because the hour indicated is the floor value
#"Premieres in 1 hour" means stream will start in around 1-2 hours

infile="$1"
invidious="$2"

echo "Start: "`date` | tee out.txt
echo "----------------------" | tee -a out.txt
cat "$infile" | while read ch
do
curl "${invidious}/channel/${ch}/streams" | grep -B60 ">0 view" > clip.tmp
if test -s clip.tmp
then
echo "--" >> clip.tmp
endl=`cat clip.tmp | wc -l`
begl=`expr $endl - 60`
while test $begl -gt 0
do
sed -n "${begl},${endl}p" clip.tmp > info.tmp
url=`grep "Watch on YouTube" info.tmp | cut -d'"' -f4 | cut -d'/' -f4`
time_info=""
if grep -q Shared info.tmp
then time_info="A LITERAL 0 VIEW VOD"
else time_info=`grep Premieres info.tmp | cut -d'>' -f2 | cut -d'<' -f1`
fi
if test -z "$time_info"
then time_info="Live"
fi
echo
echo "${time_info} + "`grep channel-name info.tmp | cut -d'>' -f2`" + "`grep "a href=\"/${url}\"" info.tmp | cut -d'>' -f3 | cut -d'<' -f1`" + https://www.youtube.com/${url}" | tee -a out.txt
echo
endl=$begl
begl=`expr $endl - 60`
done
fi
done
echo "----------------------" | tee -a out.txt
echo "End: "`date` | tee -a out.txt
echo
echo
Edit
Pub: 31 Mar 2024 05:33 UTC
Edit: 15 Apr 2024 02:22 UTC
Views: 115