Skip to content

Instantly share code, notes, and snippets.

@aliva
Last active December 13, 2015 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliva/8101aa28f08cfe23454a to your computer and use it in GitHub Desktop.
Save aliva/8101aa28f08cfe23454a to your computer and use it in GitHub Desktop.
#!/bin/bash
TIMEOUT=1
function do_action(){
player=$1
action=$2
# check if player is running
if ! pgrep $player &>/dev/null
then
return
fi
# if it wants some crappy info
if [[ $action == "info" ]]
then
case $player in
deadbeef)
deadbeef --nowplaying '%t - %a' 2>/dev/null
return
;;
rhythmbox)
rhythmbox-client --print-playing-format="%tt by %ta"
return
;;
clementine)
qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.GetMetadata \
| sort -r | egrep "^(title:|artist:)" | sed -e "s/^.*: //g" | sed -e ':a;N;$!ba;s/\n/ by /g'
return
;;
esac
fi
if [[ $player == "deadbeef" ]]
then
# deadbeef
$TIMEOUT $player "--$action"
exit
fi
case $action in
prev)
action="previous"
;;
play-pause)
action="PlayPause"
;;
info)
# TODO
echo "TODO!"
;;
esac
action="${action^}"
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.$player /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$action
exit
}
if [ -z $1 ]
then
echo "[play-pause|stop|next|prev|info]"
exit
fi
#players="deadbeef clementine rhythmbox vlc"
players="quodlibet clementine vlc rhythmbox"
if [ -z $2 ]
then
for player in $players
do
do_action $player $1
done
else
do_action $1 $2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment