Add mpris script to retreive now-playing information from compatible players via...
[quassel.git] / data / scripts / mpris
1 #!/usr/bin/env perl
2 # Copyright 2009 Sebastian Goth seezer@roath.org
3
4 # Simple script to read metadata from mpris compatible mediaplayers via dbus.
5 #
6 # Run it like this:
7 # mpris amarok
8 #
9 # The script fills all fields exported by the player's dbusinterface.
10 # They are defined here: http://wiki.xmms2.xmms.se/wiki/MPRIS_Metadata
11 #
12 # To see which fields are actually available from your player,
13 # call something like this from a terminal:
14 #
15 # qdbus org.mpris.amarok /Player GetMetadata
16 # or
17 # qdbus org.mpris.vlc /Player GetMetadata
18 # etc.
19
20 # Every field is available in the data hash 'd' via
21 # $d{"NAME_OF_FIELD"}
22 # To edit the output just change the marked line accordingly.
23
24 use strict;
25 my %d;
26
27 if($#ARGV < 0) {
28  print STDERR "Usage: $0 playername\n";
29  exit 1;
30 }
31
32 die "Please don't use any special characters in playername." if($ARGV[0] =~ /[^\w\d_-]/);
33
34 open(IN,"qdbus org.mpris.".$ARGV[0]." /Player GetMetadata|") or die "Couldn't get dbus result.";
35 while(<IN>) {
36         $d{$1} = $2 if(/^([^:]+):\s+([^\n]+)/);
37 }
38 close IN;
39
40 if(keys(%d)) {
41
42 ## change the following line to fit your needs ##
43 print "I'm listening to ".$d{"title"}." by ".$d{"artist"};
44 #################################################
45
46 print "\n";
47 }