perlquestion
morgon
Hi<p>
I have a gnome-shell extension that displays artist and title of the current song in the top bar.<p>
This extension gets the information via mpris2 (a d-bus interface) that is currently fed by cantana (a mpd-client) that controls a mpd-player on a remote machine.<p>
This works nicely for local content, but not for streams because then (for whatever reason) cantata does not seem to feed the mpris2-interface.<p>
As the strings that cantata receives from mpd need to be a bit mangled anyway I now want to replace cantanta with a Perl-script of my own.<p>
I have figured out how to receive the information I want to display from mpd, but at the moment I cannot figure out how to feed it into the d-bus.<p>
So my question is this: Given an artist and a title (both are strings), how can I feed this data into the mpris2 interface so that it can be properly displayed?<p>
What I have figured out is how to do the opposite (i.e. retrieving artist/title from mpris2) like this:
<c>
use strict;
use Net::DBus;
use Data::Dumper;
my $bus = Net::DBus->find;
my $service = $bus->get_service("org.mpris.MediaPlayer2.cantata");
my $mpris = $service->get_object("/org/mpris/MediaPlayer2");
my $output = $mpris->Get('org.mpris.MediaPlayer2.Player', "Metadata");
print Dumper($output);
</c>
This prints e.g.:
<c>
$VAR1 = {
'mpris:length' => 287000000,
'xesam:title' => 'Giant Steps',
'xesam:album' => 'Giant Steps',
'mpris:artUrl' => 'file:///home/mh/.cache/cantata/covers/John Coltrane/Giant Steps.png',
'xesam:artist' => [
'John Coltrane'
],
'xesam:genre' => [
'Unknown'
],
'mpris:trackid' => '/com/googlecode/cantata/Track/11',
'xesam:trackNumber' => 1
};
</c>
What I guess I need to do is to implement a d-bus service that implements the proper interfaces and provides a "Metadata"-property where I would then put artist and title information but at the moment I don't know how to do that.
<p>
Any help is greatly appreciated.