Monday, May 22, 2006

mpd && asus hotkeys

A bunch of bash lines in order to use mpd in combination with Asus hotkeys.

This sript requires: netcat, xosd, asus_acpi and mpd ;).

#!/bin/bash

###################
MPD_URL="localhost"
MPD_PORT="6600"
###################

function xecho() {
echo "$1" | osd_cat --font="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*" --shadow=2 --pos=top --align=center --colour=yellow --delay=2
}

function send_command_to_mpd () {
echo $1 | nc -q1 $MPD_URL $MPD_PORT
}

function get_current_song() {
filename=`send_command_to_mpd currentsong | grep "file: " | sed -e 's/file: //'`
artist=`send_command_to_mpd currentsong | grep "Artist: " | sed -e 's/Artist: //'`
title=`send_command_to_mpd currentsong | grep "Title: " | sed -e 's/Title: //'`

if [ "$artist-$title" == "-" ] ; then
echo $filename
else
echo "$artist -- $title"
fi
}

function mpd_status () {
status=`send_command_to_mpd status`
play_or_pause=`echo $status | sed -e 's/.*state: //' -e 's/ song:.*//'`
case $play_or_pause in
play ) echo play ;;
pause ) echo pause ;;
stop ) echo stop ;;
* ) echo unknown ;;
esac
}

case "$1" in
play_pause )
case `mpd_status` in
play ) send_command_to_mpd pause && xecho "`get_current_song`" ;;
pause ) send_command_to_mpd play && xecho "`get_current_song`" ;;
stop ) send_command_to_mpd play && xecho "`get_current_song`" ;;
esac ;;
stop ) send_command_to_mpd stop && xecho "`get_current_song`" ;;
next ) send_command_to_mpd next && xecho "`get_current_song`" ;;
previous ) send_command_to_mpd previous && xecho "`get_current_song`" ;;
* ) exit 1;;
esac

exit 0

No comments:

Post a Comment