#!/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") artiste=$(printf "%-40s" "$artiste") titre=$(printf "%-40s" "$titre") 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