livestream-dl

#!/bin/bash
echo Which livestream?
read livestream
echo Best audio or Select quality?
read best
if [ "$best" = "audio" ]; then
    raw="$(youtube-dl --audio-quality 0 -g $livestream)"
else
   youtube-dl -F $livestream
   sleep 1
   read format
   raw="$(youtube-dl -f $format -g $livestream)"
fi
ffmpeg -i "$raw" -map 0 -codec:v libx264 -codec:a copy -f hls -segment_list playlist.m3u8 -segment_list_type hls -segment_list_size 10 -segment_list_flags +live -segment_time 10 -hls_flags delete_segments out.ts &

sleep 10 && vlc out.ts &
expire=$($(echo "$raw" | egrep "*expire/[0-9]+/*") | egrep "[0-9]+")
while [ 1 ]
do
  if ["$expire" = "$(date +%s)"] do
    exit
  fi
end