Hello, here's a script that polls periodically what's playing on KOIT, FM 96.5 in San Francisco (you can listen via the net), and finds lyrics from another site. Not all lyrics can be found, but most seem to be ok.

update. added \Q\E around $title since it can contain something like (.

#!/usr/bin/perl -w # # polls what's current playing on radio KOIT in San Francisco, # get the lyrics from lyricsbox.com # # TODO: (1) make the title search a little fuzzier # (2) search more sites for lyrics # (3) nicer interface? color, scrolling? # use strict; use LWP::Simple; use URI::Escape; my $nowplay = "http://koit.com/nowplay_data.cfm"; my $lyricsbox = "http://www.lyricsbox.com"; my $lyrics_list = "$lyricsbox/cgi-exe/am.cgi?a=search&p=1&l=artist&s=" +; my $last_artist = ""; my $last_title = ""; my $sleep = 60; # poll once a minute while(1){ my $data = get($nowplay); my ($artist, $title) = $data =~ m|box=(.+) - (.+)&|; $title =~ s/\W+$//g; # remove junk from end $title =~ s/^\W+//g; # remove junk from beginning if ($artist ne $last_artist && $title ne $last_title){ print "-"x40,"\n"; print "\t$artist: $title\n\n"; $last_artist = $artist; $last_title = $title; # try to get lyrics my $list = get($lyrics_list.uri_escape($artist)); my ($url) = $list =~ m|<A href="([^"]+)">\Q$title\E.*?</A></t +d>|i; if($url){ my $song = get($lyricsbox.$url); my ($ly) = $song =~ m|<PRE.*?>(.+)</PRE>|si; print $ly; }else{ print "No lyrics found from $lyricsbox\n"; } print "\n\n"; } sleep $sleep; }

In reply to Lyrics for what's playing on radio KOIT (FM 96.5 in San Francisco) by johnnywang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.