Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Expanding online radio with Google's API

by silent11 (Vicar)
on Jul 18, 2002 at 04:24 UTC ( [id://182706]=CUFP: print w/replies, xml ) Need Help??

I recently fell in love with a Seattle based public radio station, KEXP. I've found alot of new music artists from listening over the past few days , ok, it's only been 2 days. KEXP provides an 'up-to-the-minute' playlist of what they have played within the hour. I wanted a little more info on the artists than what they were giving me so I threw together a little script to access Google's DB and return the top 6 results on the band's name.
Nothing too fancy, but I'm hoping that someone can learn something from it.

-Silent11
#!/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 Soa +p 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','C +omments' )] ) -> parse($html); print $cgi->header, $cgi->start_html({-title=>'KEXP PLAYLIST',-style=>{src=>'playlis +t.css'}}), $cgi->start_table({-border=>0,-width=>900,-cellpadding=>4, -ce +llspacing=>1}); print $cgi->Tr({-class=>'head'},$cgi->td(['Time','Artist','Song','Albu +m','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', 'latin +1'); my $result = SOAP::Lite -> service("file:GoogleSearch.wsdl") -> doGoo +gleSearch(@params); $out = join "\n\t", map( { qq{ &bull; <a href="$_->{URL}">} . ($_-> +{title} || $_->{URL}) . qq{</a> <br />} } @{$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. # # # <silent11> can I reference a sub via a scalar? # <cluka> Sure. If you have a sub named routine, # you can reference it via $s = \&routine. Then call like $s->(args)

Replies are listed 'Best First'.
Re: Expanding online radio with Google's API
by hossman (Prior) on Jul 18, 2002 at 18:25 UTC
    You might be interested in the Net::Google module, which handles all of the SOAP 'work' for you.

    (God bless Facades)

Re: Expanding online radio with Google's API
by elwarren (Priest) on Jul 23, 2002 at 19:52 UTC
    $Boogle? Is that kind of like doing the Google Boogie?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://182706]
Approved by dws
Front-paged by jarich
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-29 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found