91 lines
2.4 KiB
Bash
Executable File
91 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
shopt -s checkwinsize
|
|
mpvpid=""
|
|
corn=("╭"
|
|
"╮"
|
|
"╰"
|
|
"╯")
|
|
pipe=("─"
|
|
"│")
|
|
tout=30
|
|
JQ=""
|
|
|
|
source config.sh
|
|
|
|
[ -z $JQ ] && \
|
|
{ command -v gojq &> /dev/null && JQ=gojq;} || \
|
|
{ command -v jq &> /dev/null && JQ=jq;} || \
|
|
{ echo "No jq found."; exit 1;}
|
|
|
|
|
|
command -v clear &> /dev/null || { echo "No clear found.";exit 2;}
|
|
command -v fzf &> /dev/null || { echo "No fzf found.";exit 3;}
|
|
command -v mpv &> /dev/null || { echo "No mpv found.";exit 3;}
|
|
|
|
function timeschar() {
|
|
times=${1}
|
|
string=${2}
|
|
|
|
for _ in $(seq 1 ${times})
|
|
do printf "${string}"
|
|
done
|
|
}
|
|
|
|
function printtomid() {
|
|
string=${1}
|
|
|
|
len[0]=$(((cols-(2+${#string}))/2)); len[1]=$((cols-${#string}-len[0]-2))
|
|
|
|
printf "${pipe[1]}$(timeschar ${len[0]} " ")"
|
|
printf "${string}"
|
|
printf "$(timeschar ${len[1]} " ")${pipe[1]}\n"
|
|
}
|
|
|
|
jsonData="$(curl -s "$url"/status-json.xsl)"
|
|
export leng=$(($($JQ '.icestats.source | length' <<< "${jsonData}") - 1))
|
|
radios=()
|
|
urls=()
|
|
titles=()
|
|
|
|
for song in $(seq 0 ${leng})
|
|
do radios+=("`$JQ ".icestats.source[${song}].server_name" <<< "${jsonData}" | sed 's|^\"||g;s|\"$||g'`")
|
|
urls+=("`$JQ ".icestats.source[${song}].listenurl" <<< "${jsonData}" | sed 's|^\"||g;s|\"$||g'`")
|
|
done
|
|
|
|
printf '\033[?1049h\033[0H' # start alternative buffer thing
|
|
while :
|
|
do clear
|
|
jsonData="$(curl -s "$url"/status-json.xsl)"
|
|
titles=()
|
|
for index in `seq 0 ${leng}`
|
|
do titles+=("`$JQ ".icestats.source[${index}].title" <<< "${jsonData}" | sed 's|^\"||g;s|\"$||g'`")
|
|
done
|
|
[ -n "${select}" ] && {
|
|
[ -n "$mpvpid" ] && kill $mpvpid
|
|
mpv "${urls[${select}]}" &>/dev/null&
|
|
mpvpid=$!
|
|
}
|
|
|
|
[ -n "${select}" ] || select=${last}
|
|
cols=${COLUMNS:-$(tput cols)}
|
|
lins=${LINES:-$(tput lines)}
|
|
printf "${corn[0]}$(timeschar $((cols-2)) "${pipe[0]}")${corn[1]}\n"
|
|
printtomid
|
|
printtomid "${radios[${select}]} : ${titles[${select}]}"
|
|
printtomid
|
|
printf "${corn[2]}$(timeschar $((cols-2)) "${pipe[0]}")${corn[3]}\n"
|
|
|
|
list="$(
|
|
for index in `seq 0 ${leng}`
|
|
do echo "$index ${radios[${index}]} : ${titles[${index}]}"
|
|
done
|
|
)"
|
|
last=${select}
|
|
select=$(timeout --foreground ${tout} fzf --reverse --height=~25 <<< "$(printf "$list\nq exit")"| awk '{print $1}')
|
|
[ "${select}" == "q" ] && {
|
|
kill $mpvpid 2>/dev/null
|
|
printf '\033[?1049l' # stop alternative buffer thing
|
|
exit
|
|
}
|
|
done
|