Skip to content

Instantly share code, notes, and snippets.

@tom-flamelit
Last active January 11, 2025 03:34
Show Gist options
  • Save tom-flamelit/461b429270d830c76d3d6294acea823c to your computer and use it in GitHub Desktop.
Save tom-flamelit/461b429270d830c76d3d6294acea823c to your computer and use it in GitHub Desktop.
ZSH Functions for music streams
#!/bin/zsh
function listen_soma() {
local playlist=$1
local stations_url="https://api.somafm.com/channels.json"
local station_info=$(curl -s "$stations_url" | jq -r --arg station "$playlist" '.channels[] | select(.id == $station)')
if [[ -n "$station_info" ]]; then
local pls_url=$(echo "$station_info" | jq -r '.playlists[] | select(.format == "mp3" and .quality == "highest") | .url')
if [[ -n "$pls_url" && "$pls_url" != "null" ]]; then
echo "Playing station: $playlist"
mpv "$pls_url"
else
echo "$station_info"
echo "No valid .pls URL found for station: $playlist"
fi
else
echo "Station not found. Check your input."
fi
}
function listen_bbc_radio3() {
local bbc_stream_url="http://as-hls-ww-live.akamaized.net/pool_900/live/ww/bbc_radio_three/bbc_radio_three.isml/bbc_radio_three-audio%3d96000.norewind.m3u8"
if command -v mpv > /dev/null; then
echo "Playing BBC Radio 3..."
mpv "$bbc_stream_url"
else
echo "mpv is not installed. Please install mpv to use this function."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment