Files
fip_explorer/fip.sh
2023-11-23 15:38:05 +01:00

55 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
colors=("31" "32" "33" "34" "35" "36" "37")
color_index=0
function get_next_color() {
local current_color_index="$1"
local next_color_index=$(( (current_color_index + 1) % ${#colors[@]} ))
echo "$next_color_index"
}
function print_data() {
local json_data="$1"
local output=""
IFS=$'\n'
for item in $(echo "$json_data" | jq -c '.[]'); do
slug=$(echo "$item" | jq -r '.slug')
titre=$(echo "$item" | jq -r '.now.song.title')
artiste=$(echo "$item" | jq -r '.now.secondLine')
slug=${slug#fip_}
slug="$(tr '[:lower:]' '[:upper:]' <<< ${slug:0:1})${slug:1}"
color_code=${colors[$color_index]}
slug="\033[1;${color_code}m$slug\033[0m"
slug=$(printf "%-32s" "$slug")
terminal_width=$(tput cols)
width=$((((terminal_width - 32) / 2) - 4))
artiste=$(printf "%-${width}s" "${artiste:0:${width}}")
titre=$(printf "%-${width}s" "${titre:0:${width}}")
output+="\033[1$slug\033[0m | \033[1mArtiste:\033[0m $artiste | \033[1mTitre:\033[0m $titre |\n"
color_index=$(get_next_color "$color_index")
done
clear
echo -e "$output"
}
md5=""
while true; do
json_data=$(curl -s "https://www.radiofrance.fr/fip/api/webradios?station=fip")
new_md5=$(echo -n "$json_data" | md5sum | awk '{print $1}')
if [ "$new_md5" != "$md5" ]; then
print_data "$json_data"
md5="$new_md5"
fi
sleep 5
done