From 22d2105058e11dde492135fb9223d0f97e76a5b7 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Mon, 13 Jan 2020 15:45:51 +0000 Subject: [PATCH] Adds radio script --- bin/.bin/radio | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 bin/.bin/radio diff --git a/bin/.bin/radio b/bin/.bin/radio new file mode 100755 index 00000000..9761b459 --- /dev/null +++ b/bin/.bin/radio @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +LIST="$HOME/.local/share/radioStations" +PLAY="mpv --input-ipc-server=/tmp/mpvsocket" + +function getRadioStations(){ + echo "Updating radio stations" + curl -s http://www.radiofeeds.co.uk/pda/search.asp\?search\=+ |\ + hq p data |\ + grep 'href=' |\ + sed -e 's/<\/\?font[^>]*>//g' |\ + while read line; do + name="$(echo $line | hq b text | head -n 1)" + echo "$(echo $line | hq a data)" | while read stream; do + url="$(echo $stream | hq a attr href)" + quality="$(echo $stream | hq a text)" + echo "$name $quality $url" + done + done > "$LIST" +} + +function playStation(){ + if [ ! -e "$LIST" ]; then + getRadioStations + fi + cat "$LIST" | fzf --no-preview | cut -d' ' -f3 | xargs $PLAY +} + + +if [ -n "$1" ]; then + while [ -n "$1" ]; do + case "$1" in + "-u"|"--update") + getRadioStations + exit + ;; + *) + playStation + esac + done +else + playStation +fi