#!/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 $musicsong = "http://www.musicsonglyrics.com"; my $matrix = "http://www.ntl.matrix.com.br"; my ($last_artist,$last_title) = ("",""); my $sleep = 60; # poll once/min select((select(STDOUT), $| = 1)[0]); # autoflush STDOUT my $data; while(1){ while (!($data = get($nowplay))) { print "*"; sleep $sleep; next; } my ($artist, $title) = $data =~ m|box=(.+) - (.+)&|; for ($title) { s/\W+$//g; s/^\W+//g; } # rm head&trail junk my ($a1,$t1,$a,$t,$r) = (substr($artist,0,1), substr($title,0,1)); if ($artist ne $last_artist && $title ne $last_title){ # NowPlaying on KOIT print "\n","-"x50,"\n"; print "[$artist]: [$title]\n\n"; ($last_artist, $last_title) = ($artist, $title); my ($list, $url, $song); my $ly = ""; # Lyrics from lyricsbox? $list = get($lyrics_list.uri_escape($artist)); ($url) = $list =~ m|\Q$title\E.*?|i; if ($url) { $song = get($lyricsbox.$url); } if ($song) { ($ly) = $song =~ m|