somafm (836B)
1 #!/bin/sh 2 3 root=https://somafm.com/ 4 stream="$root/%s256.pls" 5 index=$(curl -qs "$root" | awk ' 6 BEGIN { 7 station=0 8 } 9 10 /^<li class="cbshort">/ { 11 station=1 12 } 13 14 /^<\/li>/ { 15 station=0 16 } 17 18 /^<a href="/ && station { 19 sub(/[^"]*"\//, "") 20 sub(/\/".*/, "") 21 printf "%-15s\t", $0 22 } 23 24 /^<h3>/ && station { 25 gsub(/<\/?h3>/, "") 26 printf "%s - ", $0 27 } 28 29 /^<p/ && station { 30 sub(/<p[^>]*>/, "") 31 sub(/<\/p>/, "") 32 printf "%s\n", $0 33 }') 34 35 while : 36 do 37 trap 'exit' 2 38 printf "\n%s\n> " "$index" 39 read -r input 40 41 [ "$input" = "quit" ] || [ "$input" = "q" ] && exit 42 43 echo "$index" | awk -v "input=$input" ' 44 $1 == input {exists=1} 45 END {if (!exists) exit 1}' || { 46 printf '%s\n' "no such station" 47 continue 48 } 49 50 ( 51 mpv $(printf "$stream" "$input") 2>&1 | 52 grep 'icy-title' | sed 's/[^:]*: /Playing: /' 53 ) & 54 mpvpid="$!" 55 trap 'kill $mpvpid' 2 56 wait 57 done