winamp lyrics script
rush3k
created: 2006-04-15 19:23:45
Started learning Perl two weeks ago .. this is my first script .. it reads current song playing on Winamp and displays lyrics from the azlyrics website on the DOS terminal. However its dependent on httpq installation ... is there a way I can get the current song playing information from Windows?
use strict;
use Winamp::Control;
use WWW::Mechanize;
use warnings;

my $agent = Winamp::Control -> new (host => '127.0.0.1', port => '4800', passwd => 'pass');

my $playing = $agent->getcurrenttitle();
my $artistsong = $agent->getcurrenttitle();
   $artistsong =~ s/\d.*?\s//s;

my $firstletter = $artistsong;
   $firstletter = substr($artistsong,0,1);

my $artistname = $artistsong;
   $artistname =~ s/ -.*//s;
   $artistname =~ tr/a-z/A-Z/;
   
my $songtitle = $artistsong;
   $songtitle =~ s/.*- //s;
   
my $lyrics = WWW::Mechanize -> new (autocheck => 1);
   $lyrics -> get('http://www.azlyrics.com/');
   $lyrics -> follow_link(text => $firstletter, n => 1);
   $lyrics -> follow_link(text => $artistname, n => 1);
   $lyrics -> follow_link(text => $songtitle, n => 1);
my $content1 = $lyrics -> content(format => "text");
   
print "$artistname";
print "$songtitle \n";
print $content1;

Re: winamp lyrics script
created: 2006-04-22 15:08:06
Cool script! An interesting alternative would be to find a site that offered lyrics in XML format and use XML::Simple to parse that. I don't know of any such sites, though.

Also, what do you do if the lyrics site doesn't have the song? Does WWW::Mechanize complain?

Here are a few pointers:

If you're going to do a substr() on a scalar and save the result into another scalar, you don't need to explicity copy the scalar first. You can just do:

my $firstletter = substr($artistsong,0,1);

Also, for translating something entirely to capitals, perl has a builtin:

$songtitle = uc $songtitle;

Re: winamp lyrics script
created: 2006-04-25 13:20:44
I have no clue whether it is possible or not, but I've seen scripts (not in perl), that use dde to pull the info straight from the player. Try looking for AMIP for winamp, although I don't know if that will be helpful or not. Good luck!

perlmonks.org content © perlmonks.org and Anonymous Monk, mpeg4codec, rush3k

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03