in reply to Re^2: Lyrics for what's playing on radio KOIT (FM 96.5 in San Francisco)
in thread Lyrics for what's playing on radio KOIT (FM 96.5 in San Francisco)

Seems the problem is with the lyricsbox.com site (404 err)
I tried switching to musicsonglyrics.com, and that loks better (tho' my hack is pure screen scraping...)
Could be nice if you get some time to fix it!

____________________________________________________
Update April 19: added yet another lyrics channel... -- allan
____________________________________________________
Update April 26: updated code (incl TK GUI) in node 450914
____________________________________________________
#!/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|<A href="([^"]+)">\Q$title\E.*?</A></td>| +i; if ($url) { $song = get($lyricsbox.$url); } if ($song) { ($ly) = $song =~ m|<PRE.*?>(.+)</PRE>|si; } if ($ly) { print "Lyrics: $lyricsbox\n\n $ly\n\n"; next; } else { print "No lyrics: $lyricsbox\n"; } # Lyrics from matrix? ($a, $t) = ($artist, $title); for ($t) { s/\s/_/g; s/\'//g; } foreach my $p ("html/lyrics/$t1", "oldies_list/top/lyrics") { $url = lc("pfilho/$p/${t}.txt"); $ly = get("$matrix/$url"); last if $ly; } if ($ly) { for ($ly) { s/^\s+//; s/\s+$//; } print "Lyrics: $matrix\n\n $ly\n\n"; next; } else { print "No lyrics: $matrix\n"; } # Lyrics from musicsong? ($a, $t) = ($artist, $title); for $r (\$a, \$t) { $$r =~ s/\s//g; $$r = lc($$r); } $url = "$a1/${a}lyrics/$a${t}lyrics.htm"; $song = get("$musicsong/$url"); if ($song) { ($ly) = $song =~ m|<span.*?>(.+)</span>|si; } if ($ly) { for ($ly) { s/^\s+//; s/\s+$//; s/<.*?>//gi; } print "Lyrics: $musicsong\n\n $ly\n\n"; next; } else { print "No lyrics: $musicsong\n"; } } else { print "."; } sleep $sleep; }

-- Allan

===========================================================
As the eternal tranquility of Truth reveals itself to us, this very place is the Land of Lotuses

-- Hakuin Ekaku Zenji
  • Comment on Re^3: Lyrics for what's playing on radio KOIT (FM 96.5 in San Francisco)
  • Download Code