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; }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |