This commit is contained in:
mertoalex 2023-12-11 01:56:04 +03:00
parent 0f0347462d
commit 08c23a5bac
2 changed files with 96 additions and 0 deletions

2
config.sh Normal file
View File

@ -0,0 +1,2 @@
#!/usr/bin/bash
url="https://radio.vern.cc"

94
main.sh Executable file
View File

@ -0,0 +1,94 @@
#!/usr/bin/bash
source config.sh
corn=("╭"
"╮"
"╰"
"╯")
pipe=("─"
"│")
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))
#len=($(((cols-(2+${#string}))/2)) $(((cols-2)/2-${#string}/2)))
printf "${pipe[1]}$(timeschar ${len[0]} " ")"
printf "${string}"
printf "$(timeschar ${len[1]} " ")${pipe[1]}\n"
}
#function printtomids() {
# string=(${1} ${2} ${3})
#
# len[0]=$(((cols-(2+(${#string[0]}+${#string[1]}+${#string[2]})))/6))
# len[1]=$((len[0]*2-${#string[1]}))
# len[2]=$((len[0]*2-(${#string[0]}+${#string[1]}+${#string[2]})))
# len[3]=$((cols-((${#string[0]}+${#string[1]}+${#string[2]})+len[0]+len[1]+len[2])-2))
#
# printf "${pipe[1]}$(timeschar ${len[0]} " ")"
# printf "${string[0]}"
# printf "$(timeschar ${len[1]} " ")"
# printf "${string[1]}"
# printf "$(timeschar ${len[2]} " ")"
# printf "${string[2]}"
# printf "$(timeschar ${len[3]} " ")${pipe[1]}\n"
#}'
#some test:
#string="12345"; len[0]=$(((cols-(2+${#string}))/2));len[1]=$((cols-${#string}-len[0]-2)); echo "${len[0]}, ${len[1]}, $((len[0] + len[1])), $((len[0] + len[1] + ${#string} + 2)), $cols"
read -r jsonData <<< "$(curl -s https://radio.vern.cc/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'`")
titles+=("`jq ".icestats.source[${song}].title" <<< "${jsonData}" | sed 's|^\"||g;s|\"$||g'`")
#echo "hi"
done
while :
do pkill mpv
mpv "${urls[${select}]}" &>/dev/null&
echo "${urls[${select}]}"
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 "${radios[${select}]} : ${titles[${select}]}"
printf "${pipe[1]}$(timeschar $((cols-2)) " ")${pipe[1]}\n"
printf "${corn[2]}$(timeschar $((cols-2)) "${pipe[0]}")${corn[3]}\n"
select=$(
echo -e "$(
for index in `seq 0 ${leng}`
do echo "$index ${radios[${index}]} : ${titles[${index}]}"
done
)\nq exit" | fzf --reverse --height=~25 | awk '{print $1}')
clear
[ "x${select}" == "xq" ] && pkill mpv && exit
done
#for index in `seq 0 ${len}`
#do echo "("
# echo ${radios[${index}]}
# echo ${urls[${index}]}
# echo ${titles[${index}]}
# echo ")"
#done