-
-
Save werkshy/5826349 to your computer and use it in GitHub Desktop.
Digitally Imported MPD Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Play a Digitally Imported station via MPD | |
# | |
# Usage: | |
# di list | |
# di trance | |
# di breaks | |
# | |
# Config: | |
# - Modify 'bookmarks' to point to your bookmarks file. | |
# Bookmarks file should contain lines of quoted URLS. | |
# In my case I'm using my RadioTray bookmarks. Any di.fm bookmarks will be detected. | |
# | |
# Completion: | |
# - Add this to your .bashrc: | |
# _di() { | |
# local cur=${COMP_WORDS[COMP_CWORD]} | |
# COMPREPLY=( $(compgen -W "$(di list | xargs)" -- $cur) ) | |
# } | |
# complete -F _di di | |
arg=$1 | |
bookmarks=$HOME/local/radiotray/bookmarks.xml | |
function get_stations() { | |
grep -E -o 'http://listen\.di\.fm[^"]*' $bookmarks | |
} | |
function get_name() { | |
echo $1 | awk -F '/' '{print $5}' | sed 's/\.pls?.*//' | |
} | |
function list_stations() { | |
for station in $(get_stations); do | |
get_name $station | |
done | |
} | |
if [ "$arg" == "list" ]; then | |
list_stations | sort | |
exit | |
fi | |
found="" | |
for station in $(get_stations); do | |
name=$(get_name $station) | |
if [ "$arg" == "$name" ]; then | |
found=$station | |
fi | |
done | |
if [ "$found" == "" ]; then | |
echo "$arg not found" | |
exit 1 | |
fi | |
function play() { | |
playlist=$1 | |
echo "Retrieving $playlist" | |
url=$(curl "$playlist" 2>/dev/null | grep "File" | sed 's/File.*=//'|head -1) | |
mpc clear | |
mpc add "$url" | |
mpc play | |
} | |
play $found |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this to ~/.bashrc for command-line completion | |
# 'di' completetion | |
_di() { | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "$(di list | xargs)" -- $cur) ) | |
} | |
complete -F _di di |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment