Compare commits
2 Commits
f842cbe434
...
a2c6b21f0d
Author | SHA1 | Date |
---|---|---|
mertoalex | a2c6b21f0d | |
mertoalex | e33f6b2b11 |
|
@ -1,2 +1,2 @@
|
|||
#!/usr/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
url="https://radio.vern.cc"
|
||||
|
|
105
main.sh
105
main.sh
|
@ -1,16 +1,31 @@
|
|||
#!/usr/bin/bash
|
||||
source config.sh
|
||||
#!/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
|
||||
|
@ -18,76 +33,56 @@ function timeschar() {
|
|||
|
||||
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))
|
||||
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'`")
|
||||
titles+=("`jq ".icestats.source[${song}].title" <<< "${jsonData}" | sed 's|^\"||g;s|\"$||g'`")
|
||||
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
|
||||
|
||||
while :
|
||||
do [ "x$mpvpid" != "x" ] && 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 "$(
|
||||
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
|
||||
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
|
||||
exit
|
||||
}
|
||||
done
|
||||
|
||||
#for index in `seq 0 ${len}`
|
||||
#do echo "("
|
||||
# echo ${radios[${index}]}
|
||||
# echo ${urls[${index}]}
|
||||
# echo ${titles[${index}]}
|
||||
# echo ")"
|
||||
#done
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue