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;
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;
perlmonks.org content © perlmonks.org and Anonymous Monk, mpeg4codec, rush3k
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03