Perl script for Xchat to show whats going on in Pithos
Save this to ~/.xchat2/pithosplayer.pl and make it executable
in xchat, run it as
/pit_play
#!/usr/bin/perl
## pithosplayer.pl
## Perl script for Xchat to show whats going on in Pithos
use strict;
use Net::DBus;
# Pithos XChat script
# (c) Copyright 2014 - VSIDO/VastOne>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
my $script_name = "Pithos XChat";
my $script_version = " 0.0.6";
my $script_description = "Displays the current Pithos playing song in XChat.";
my $bus = Net::DBus->session;
#check for Pithos on Dbus
pit_live();
# message string
my $playing ="is listening to"; #replace with your own message
Xchat::register($script_name,$script_version,$script_description,"");
Xchat::print("Loaded \002".$script_name.$script_version."\003:");
Xchat::hook_command("pit_start", "pit_live");
Xchat::hook_command("pit_play", "pit_play");
#print "/me utilise $script_name $script_version \n";
sub pit_play{
if (pit_run()){
my $service = $bus->get_service('net.kevinmehall.Pithos');
my $object = $service->get_object('/net/kevinmehall/Pithos', 'net.kevinmehall.Pithos');
my $info= $object->GetCurrentSong;
# hash keys are : album, artist, disc, length, title, track
# $info hash contains the keys value above. you can change below to display information you need. keep "me" (command will generate the slash).
Xchat::command "me $playing $info->{artist} - $info->{title} - from the album $info->{album} playing in Pithos";
}
}
sub pit_live{
my $localbus = Net::DBus->find;
my $localservice = $localbus->get_service("org.freedesktop.DBus");
my $localobject = $localservice->get_object("/org/freedesktop/DBus");
my $gtrouver=0;
foreach (@{$localobject->ListNames}) {
if (m/pithos/){
Xchat::print "found pithos\n";
$gtrouver=1;
last;
}
}
}
sub pit_run{
my $localbus = Net::DBus->find;
my $localservice = $localbus->get_service("org.freedesktop.DBus");
my $localobject = $localservice->get_object("/org/freedesktop/DBus");
my $gtrouver=0;
foreach (@{$localobject->ListNames}) {
if (m/pithos/){
#Xchat::print "found pithos\n";
$gtrouver=1;
last;
}
}
unless ($gtrouver){
Xchat::print "You need to restart pithos use pit_start.\n";
}
return $gtrouver;
}
Much appreciated VastOne! 8)