#!/usr/bin/perl -w

# xmms script for konversation
# made by Magnus Romnes (gromnes@online.no)
# this script depends on the infopipe perlmodule made by Thomas R. Sibley
# http://search.cpan.org/src/TSIBLEY/XMMS-InfoPipe-0.032/lib/XMMS/InfoPipe.pm
# and the infopipe plug-in for XMMS written by Urpo Lankinen
# http://www.beastwithin.org/users/wwwwolf/code/xmms/infopipe.html
# as a result of using infopipe, this script uses some time to get the data.
# use the code for whatever you wish :-)

require XMMS::InfoPipe;

$PORT = shift;
$SERVER = shift;
$TARGET = shift;

my $xmms = XMMS::InfoPipe->new();

if($xmms->is_running() && $xmms->is_playing())
	{
	$song = $xmms->{info}->{Title};
	$sec_pos = $xmms->{info}->{uSecPosition};
	$sec_tot = $xmms->{info}->{uSecTime};
	$time_pos = $xmms->{info}->{Position};
	$time_tot = $xmms->{info}->{Time};
	$donepercent = int(($sec_pos*100)/$sec_tot);
	exec("dcop $PORT Konversation say $SERVER \"$TARGET\" \"/me plays: '$song' ($time_pos/$time_tot - $donepercent%)\"");
	}
elsif(!$xmms->is_running())
	{
	exec("dcop $PORT Konversation error \"xmms is not running.\"");
	}
elsif($xmms->is_paused())
        {
        exec("dcop $PORT Konversation error \"xmms is paused.\"");
        }
elsif(!$xmms->is_playing())
	{
	exec("dcop $PORT Konversation error \"xmms is not playing.\"");
	}


