#!/bin/sh
#
# somafm

set -e

reformat() {
  jq -r '.channels[] | "\u001b[36m\(.id)\u001b[0m\t\u001b[1m\(.title)\u001b[0m\t\u001b[33m\(.genre)\u001b[0m\t\(.listeners)\t\(.playlists[] | select((.format == "aac" or .format == "aacp") and .quality == "highest") | .url)\t\(.description)"'
}

choose() {
  fzf --delimiter '\t' --ansi --tabstop=23 --with-nth 2,1,3 \
    --preview 'echo {2} "  " "("{1}")"; echo Genre: {3}; echo; echo {6}; echo; echo {5}; echo Currently {4} listeners.' \
    --bind 'enter:become(mpv {5})'
}

curl -s https://somafm.com/channels.json | reformat | choose
