commit 6ebe4a31dc09c07110ae59886efd3510e9e31f28
parent 297ac683252b1a0b801b13ed02e7e954b79f25d8
Author: hhvn <dev@hhvn.uk>
Date: Mon, 5 Jul 2021 17:31:30 +0100
.s/b/somafm: somafm client
Diffstat:
1 file changed, 57 insertions(+), 0 deletions(-)
diff --git a/.scripts/bin/somafm b/.scripts/bin/somafm
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+root=https://somafm.com/
+stream="$root/%s256.pls"
+index=$(curl -qs "$root" | awk '
+BEGIN {
+ station=0
+}
+
+/^<li class="cbshort">/ {
+ station=1
+}
+
+/^<\/li>/ {
+ station=0
+}
+
+/^<a href="/ && station {
+ sub(/[^"]*"\//, "")
+ sub(/\/".*/, "")
+ printf "%-15s\t", $0
+}
+
+/^<h3>/ && station {
+ gsub(/<\/?h3>/, "")
+ printf "%s - ", $0
+}
+
+/^<p/ && station {
+ sub(/<p[^>]*>/, "")
+ sub(/<\/p>/, "")
+ printf "%s\n", $0
+}')
+
+while :
+do
+ trap 'exit' 2
+ printf "\n%s\n> " "$index"
+ read -r input
+
+ [ "$input" = "quit" ] || [ "$input" = "q" ] && exit
+
+ echo "$index" | awk -v "input=$input" '
+ $1 == input {exists=1}
+ END {if (!exists) exit 1}' || {
+ printf '%s\n' "no such station"
+ continue
+ }
+
+ (
+ mpv $(printf "$stream" "$input") 2>&1 |
+ grep 'icy-title' | sed 's/[^:]*: /Playing: /'
+ ) &
+ mpvpid="$!"
+ trap 'kill $mpvpid' 2
+ wait
+done