cute update

This commit is contained in:
mertoalex 2023-12-11 19:01:56 +03:00
parent e33f6b2b11
commit a2c6b21f0d
1 changed files with 31 additions and 37 deletions

68
main.sh
View File

@ -7,39 +7,25 @@ corn=("╭"
"╯")
pipe=("─"
"│")
tout=30
JQ=""
source config.sh
[ -z $JQ ] &&
if command -v gojq &> /dev/null
then JQ=gojq
elif command -v jq &> /dev/null
then JQ=jq
else echo "No jq found."
exit 1
fi
[ -z $JQ ] && \
{ command -v gojq &> /dev/null && JQ=gojq;} || \
{ command -v jq &> /dev/null && JQ=jq;} || \
{ echo "No jq found."; exit 1;}
if ! command -v clear &> /dev/null
then echo "No clear found."
exit 2
fi
if ! command -v fzf &> /dev/null
then echo "No fzf found."
exit 3
fi
if ! command -v mpv &> /dev/null
then echo "No mpv found."
exit 3
fi
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
@ -47,46 +33,54 @@ function timeschar() {
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"
}
read -r jsonData <<< "$(curl -s "$url"/status-json.xsl)"
jsonData="$(curl -s "$url"/status-json.xsl)"
export leng=$(($($JQ '.icestats.source | length' <<< "${jsonData}") - 1))
radios=()
urls=()
titles=()
for song in `seq 0 ${leng}`
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'`")
titles+=("`$JQ ".icestats.source[${song}].title" <<< "${jsonData}" | sed 's|^\"||g;s|\"$||g'`")
done
clear
while :
do [ -n "$mpvpid" ] && kill $mpvpid
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"
printf "${pipe[1]}$(timeschar $((cols-2)) " ")${pipe[1]}\n"
printtomid
printtomid "${radios[${select}]} : ${titles[${select}]}"
printf "${pipe[1]}$(timeschar $((cols-2)) " ")${pipe[1]}\n"
printf "${corn[2]}$(timeschar $((cols-2)) "${pipe[0]}")${corn[3]}\n"
printtomid
printf "${corn[2]}$(timeschar $((cols-2)) "${pipe[0]}")${corn[3]}\n"
select=$(
echo -e "$(
list="$(
for index in `seq 0 ${leng}`
do echo "$index ${radios[${index}]} : ${titles[${index}]}"
done
)\nq exit" | fzf --reverse --height=~25 | awk '{print $1}')
clear
)"
last=${select}
select=$(timeout --foreground ${tout} fzf --reverse --height=~25 <<< "$(printf "$list\nq exit")"| awk '{print $1}')
[ "${select}" == "q" ] && {
kill $mpvpid 2>/dev/null
exit