This time I want to write a short article about something completely different than AutoYaST or anything in that area.
Since I switched to KDE4 with amarok2, my little 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 and so I had to google a bit and rewrite the eMail-signature script for kmail and write a new little script for xchat too.
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 my little xchat2 script for example:
#!/usr/bin/perl
use strict;
Xchat::register("wumprock","1.0","Amarok xchat info");
IRC::print("Wumprock 1.0 for XChat \cB\cC3loaded\cC0 :)");
IRC::add_command_handler("curplay", "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 '$TITLE' by '$ARTIST'");
}
You can use /cur_play then in xchat to let everyone who cares (and not) know what you are listening to.
I have a smilar script for kmail to, so I can add the "now playing:" line under my signature but it looks quite the same and so I'll not paste it here.·
happy listening - Uwe
3 comments:
do you know how to use the dbus interface to query the collection?
Hi,
thanks for the post. I had to switch to your solution after amarok2 stopped using dcop, what my old script was written for :)
Gruss,
Wojtek
Thank you for this so much! I've been looking all over for a solution.
And I have modified this a bit to include playback controls (except for volume and track jumping) :)
Thank you very much!
Post a Comment