2009-08-01, 14:00
While browsing the LCDProc source to see how feasible it was to add support for the icons round the edge of the display I discovered that LCDProc already has a command in the protocol (OUTPUT) which can be customised in each driver and in the imon lcd driver this command controls the additional display icons.
After discovering this i figured rather than modifying xbmc sourcecode it would be quite simple to write a perl script that runs in the background and queries xbmc via the http interface and lights up icons based on the currently playing file.
Here is my first attempt. It does work and should not be too difficult to customise if you wish but doesnt have much in the way of error trapping (eg. checking the responses for LCDproc)...
After discovering this i figured rather than modifying xbmc sourcecode it would be quite simple to write a perl script that runs in the background and queries xbmc via the http interface and lights up icons based on the currently playing file.
Here is my first attempt. It does work and should not be too difficult to customise if you wish but doesnt have much in the way of error trapping (eg. checking the responses for LCDproc)...
Code:
#!/usr/bin/perl
use HTTP::Request::Common;
use LWP::UserAgent;
use IO::Socket;
my $sockres;
my $sock;
#see here for details of imon lcd driver output control bits
#http://lcdproc.cvs.sourceforge.net/viewvc/lcdproc/lcdproc/server/drivers/imonlcd.c?view=markup
$sock = new IO::Socket::INET (PeerAddr => 'localhost', PeerPort => '13666', Proto => 'tcp', );
die "Could not create socket: $!\n" unless $sock;
print $sock "hello\n";
$sockres = readline $sock;
do
{
my $output = "";
my $progress = 0;
my $icondata = 0;
my $ua = LWP::UserAgent->new;
my $res = $ua->request(GET 'http://localhost:8080/xbmcCmds/xbmcHttp?command=GetCurrentlyPlaying');
if ($res->is_success)
{
$output = $res->content;
#remove html tags
$output =~ s/<html>//gi;
$output =~ s/<.html>//gi;
$output =~ s/<li>//gi;
}
my @lines = split(/\n/, $output);
foreach my $val (@lines)
{
if ($val =~ /Filename:/i)
{
if ($val =~ /.mpg/i) { $icondata = $icondata | (1<<19) }; #turn on MPG icon
if ($val =~ /.mpeg/i) { $icondata = $icondata | (1<<19) }; #turn on MPG icon
if ($val =~ /.avi/i) { $icondata = $icondata | (2<<19) }; #turn on DIVX icon
if ($val =~ /.wmv/i) { $icondata = $icondata | (4<<19) }; #turn on WMV icon
if ($val =~ /.wma/i) { $icondata = $icondata | (3<<13) }; #turn on WMA icon
if ($val =~ /.mp3/i) { $icondata = $icondata | (1<<13) }; #turn on MP3 icon
if ($val =~ /.ogg/i) { $icondata = $icondata | (2<<13) }; #turn on OGG icon
if ($val =~ /.wav/i) { $icondata = $icondata | (4<<13) }; #turn on WAV icon
}
if ($val =~ /Type:/)
{
if ($val =~ /Video/i) { $icondata = $icondata | (2<<1) }; #turn on MOVIE icon
if ($val =~ /Video/i) { $icondata = $icondata | 1 }; # enable play animation
if ($val =~ /Audio/i) { $icondata = $icondata | (1<<1) }; # turn on MUSIC icon
if ($val =~ /Audio/i) { $icondata = $icondata | 1 }; # enable play animation
if ($val =~ /Picture/i) { $icondata = $icondata | (3<<1) }; # turn on PHOTO icon
}
if ($val =~ /Percentage:/)
{
$val =~ s/Percentage://i;
$progress = $val *32 / 100;
}
}
printf $sock "output %i\n",$icondata;
$sockres = readline $sock;
sleep 1;
printf $sock "output %i\n",(($progress <<6) | (1<<28)); # configure upper progress bar
$sockres = readline $sock;
sleep 1;
} while 1;
close $sock;