Since KDE4 with amarok2, now-playing scripts for amarok and xchat did not work anymore. The interface to query amarok for the data was changed from dcop to dbus. So, how to squeeze the information out of the new amarok2? It’s quite easy:

qdbus org.kde.amarok /Player GetMetadata

and that’s it. qtbus is part of the libqt4 package and you’ll get an output of everything that is interesting and that you can parse easily. Here is a little xchat2 script for example:

use strict;
Xchat::register("wumprock","1.0","Amarok xchat info");
IRC::print("Wumprock 1.0 for XChat cBcC3loadedcC0 :)");
IRC::add_command_handler("np", "cmd_amacurplay");
sub cmd_amacurplay {
my $META = `qdbus org.kde.amarok /Player GetMetadata`;
my ($ARTIST) = ( $META =~ /artist: (.*)/  ? $1 : "-" );
my ($TITLE)  = ( $META =~ /title: (.*)/   ? $1 : "not playing" );
my ($ALBUM)  = ( $META =~ /album: (.*)/   ? $1 : "-" );
IRC::command("/me is now playing $ARTIST - $TITLE");

You can use /np then in xchat to let everyone who cares (and not) know what you are listening to.

%d bloggers like this: