#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTML::TableExtract;
use SOAP::Lite;
use CGI;
my ($cgi, $ua, $request, $response, $html, $body, $ts, $row, $Boogle, $out);
my $GoogleKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$cgi = CGI->new();
$Boogle = \&google;
$ua = LWP::UserAgent->new;
$ua->proxy('http', ''); # enter proxy if needs be / and set it for Soap too ...
$request = HTTP::Request->new('GET', 'http://140.142.17.178/playdisp.asp');
$response = $ua->request($request);
$html = $response->as_string;
$body = new HTML::TableExtract(
headers => [('Time','Artist','Song title','Album title','Label','Comments' )] )
-> parse($html);
print $cgi->header,
$cgi->start_html({-title=>'KEXP PLAYLIST',-style=>{src=>'playlist.css'}}),
$cgi->start_table({-border=>0,-width=>900,-cellpadding=>4, -cellspacing=>1});
print $cgi->Tr({-class=>'head'},$cgi->td(['Time','Artist','Song','Album','6 Related links from Google']));
foreach $ts ($body->table_states) {
foreach $row ($ts->rows) {
my ($Time,$Artist,$Song,$Album,$Label,$Comments) = @$row;
print $cgi->Tr({-class=>'body'},
$cgi->td([$Time,$Artist,$Song,$Album,$Boogle->($Artist)])) if length($Time) > 3; # some rows are empty
}
}
sub google {
my $param = shift;
my @params = ($GoogleKey,$param, 0, 6, 0, '', 0, '', 'latin1', 'latin1');
my $result = SOAP::Lite -> service("file:GoogleSearch.wsdl") -> doGoogleSearch(@params);
$out = join "\n\t", map( { qq{ • } . ($_->{title} || $_->{URL}) . qq{
} } @{$result->{resultElements}} );
return $out;
}
#ps - don't be surprised if you get no playlist at the top of the hour
# they tend to be about one min behind the actual play-time.
#
#
# can I reference a sub via a scalar?
# Sure. If you have a sub named routine,
# you can reference it via $s = \&routine. Then call like $s->(args)