# get_xbmc.pl
# by StarG (c) 2007
#
# licenced under gplv3
# see www.gnu.org/copyleft for details
use LWP::UserAgent;
use Data::Dumper;
use strict;
require 5.6.0;
# enter here the url to the xmbc webserver including get playlist command
my $xbmc_url = "http://192.168.0.23/xbmcCmds/xbmcHttp?command=getcurrentlyplaying";
#my $xbmc_url = "http://rafb.net/p/Ha7faX68.txt";
my $xbmc_delay = 15;
my $xbmc_active = 0;
my $xmbc_version = 0.1;
initXBMC();
sub collectData {
# my $doc = get($xbmc_url);
my $doc;
my %data;
my $ua = LWP::UserAgent->new();
$ua->timeout(1);
my $request = HTTP::Request->new('GET', $xbmc_url);
my $response = $ua->request($request);
#if ( length($doc) > 0 )
if ( !$response->is_error() )
{
$doc = $response->content();
while ( $doc =~ /
(.+?):([^<]+?)$/mig )
{
my $key = $1;
my $value = $2;
chomp( $value );
chomp( $value );
$data{$key} = $value;
}
}
else
{
$data{'error'} = 1;
}
# print Dumper( \%data );
return \%data;
}
sub initXBMC {
Xchat::register( "xbmc song paster", $xmbc_version, "...", sub { } );
Xchat::hook_command( "gog", \&pasteStatusXBMC );
}
sub pasteStatusXBMC {
my $dataref = collectData();
my %data = %{$dataref} if $dataref =~ /HASH/;
my $msg;
if ( $data{'error'} ne 1 )
{
if ( defined $data{'Type'} )
{
if ( $data{'Type'} eq "Video" )
{
$msg = "[XBMC Playing] • Video • [ $data{'Title'} ] • ( $data{'Time'} / $data{'Duration'} )";
}
elsif ( $data{'Type'} eq "Audio" )
{
$msg = "[XBMC Playing] • Audio • [ $data{'Artist'} • $data{'Album'} • $data{'Title'} ] • ( $data{'Time'} / $data{'Duration'} )";
}
elsif ( $data{'Type'} eq "Picture" )
{
$msg = "[XBMC Playing] • Picture • [ $data{'Filename'} • Width:$data{'Width'} • Height:$data{'Height'} ]";
}
else
{
$msg = "unknown state";
}
}
else
{
$msg = "XBMC not playing anything!";
}
}
else
{
$msg = "XBMC offline"
}
if ( $data{'Type'} eq "Video" || $data{'Type'} eq "Audio" || $data{'Type'} eq "Picture")
{
Xchat::command("say $msg" )
}
else
{
Xchat::command("echo $msg" )
}
}
sub handleXMBC {
if ( $xbmc_active eq 0 )
{
$xbmc_active = 1;
Xchat::print( "[XBMC] showing songs!");
}
else
{
$xbmc_active = 0;
Xchat::print( "[XBMC] stopped!");
}
}
1;