Having been frustrated by the existing now-playing scripts, I wrote this one for myself. Tested on Amarok 2.2 and Kopete 0.80., feel free to extend it to Pidgin (note attached, I dont use pidgin so I cannot test it yet).
A downloadable tar installer script is also available.
Code:
#!/bin/bash
#===================================================================================
#
# FILE: amarok_now_playing
#
# USAGE: amarok_now_playing [ > logfile]
#
# DESCRIPTION: Changes your status message in pidgin and/or
# Kopete to the song you are currently listening to in Amarok.
#
# OPTIONS: see function ’usage’ below
# REQUIREMENTS: --- Amarok 2.2, Kopete 0.70
# LICENCE: GNU GPL
# NOTES: ---
# AUTHOR: Arthur Buliva, arthurbuliva [at] fedoraproject [dot] org
# COMPANY: Arthur Buliva
# VERSION: 1.0
# CREATED: 26.05.2009 - 16:17:51
# REVISION: 16.10.2009 - 12:32:36
#===================================================================================
STARTUP="qdbus org.kde.amarok / Identity"
ALLOWED_AMAROK_VERSION="2.2"
ALLOWED_KOPETE_VERSION="0.80"
PIDGIN="`kopete --version`"
#Messages to display if Amarok is not playing any song
MESSAGES=(
"Quiet",
"Amarok is Quiet",
"Long live KDE"
)
#Test for Amarok
echo -n "Checking Amarok version... "
a=`$STARTUP | cut -c 8-`
if [[ "$a" =~ "${ALLOWED_AMAROK_VERSION}" ]]
then
echo "Amarok $a [ OK ] "
else
echo -n $a;tput setaf 1;tput bold;echo -n " [ FAILED ] ";tput sgr0;echo "Make sure that you are running Amarok 1.4 | `date +%b-%d-%Y\ %T` ";
logger "$0 failed to start. Detected Amarok $a but requires Amarok $ALLOWED_AMAROK_VERSION"
exit;
fi
#Test for Kopete
echo -n "Checking Kopete version... "
if [[ "$PIDGIN" =~ "${ALLOWED_KOPETE_VERSION}" ]]
then
echo "Kopete $PIDGIN [ OK ] "
else
echo -n $a;tput setaf 1;tput bold;echo -ne "\nERROR: ";tput sgr0;echo "This script has been tested on Kopete 0.70 only | `date +%b-%d-%Y\ %T` "
logger "$0 failed to start. Detected Kopete $PIDGIN but requires Kopete 0.70"
exit
fi
updateStatus()
{
if [[ "`$STARTUP`" != "" ]]
then
SONG_TITLE="qdbus org.kde.amarok /Player GetMetadata"
ARTIST="qdbus org.kde.amarok /Player GetMetadata"
KOPETE_STATUS='qdbus org.kde.kopete /Kopete'
if [[ "`$KOPETE_STATUS`" == "" ]]
then
tput setaf 1;tput bold;echo -n "ERROR: ";tput sgr0;echo "Kopete is not running. This script will terminate | `date +%b-%d-%Y\ %T` "
logger "$0 terminated because Kopete is not running"
exit
fi
if [[ "`$SONG_TITLE | grep title: | cut -c 8-`" != "" ]]
then
TITLE="♫ `$SONG_TITLE | grep title: | cut -c 8-` by `$ARTIST | grep artist: | cut -c 9- `";
logger "$TITLE";
echo $TITLE;
#Pidgin
#`/usr/bin/purple-remote "setstatus?status=available&message=$TITLE"`
#Kopete
qdbus org.kde.kopete /Kopete org.kde.Kopete.setIdentityOnlineStatus "Online" "$TITLE"
sleep 10;
updateStatus
else
TITLE=${MESSAGES[ $[ ( $RANDOM % 1 ) + 1 ] - 1 ])};
echo $TITLE;
#Pidgin
#`/usr/bin/purple-remote "setstatus?status=available&message=$TITLE"`
#Kopete
qdbus org.kde.kopete /Kopete org.kde.Kopete.setIdentityOnlineStatus "Online" "$TITLE"
sleep 30;
updateStatus
fi
else
tput setaf 1;tput bold;echo -n "ERROR: ";tput sgr0;echo "Could not connect to DCOP Server | `date +%b-%d-%Y` "
logger "$0 Could not connect to DCOP Server"
exit
fi
}
updateStatus