Lyrics::Fetcher::LyrDB - The great new Lyrics::Fetcher::LyrDB!


Lyrics-Fetcher-LyrDB documentation Contained in the Lyrics-Fetcher-LyrDB distribution.

Index


Code Index:

NAME

Top

Lyrics::Fetcher::LyrDB - The great new Lyrics::Fetcher::LyrDB!

VERSION

Top

Version 0.02

NAME

Top

Lyrics::Fetcher::LyrDB - Get song lyrics from www.LyrDB.com

SYNOPSIS

Top

  use Lyrics::Fetcher;
  print Lyrics::Fetcher->fetch("<artist>","<song>","LyrDB");

  # or, if you want to use this module directly without Lyrics::Fetcher's
  # involvement:
  use Lyrics::Fetcher::LyrDB;
  print Lyrics::Fetcher::LyricDB->fetch('<artist>', '<song>');




DESCRIPTION

Top

This module uses LyrDB's web services to get song lyrics from www.lyrdb.com. It's designed to be called by Lyrics::Fetcher, but can be used directly if you'd prefer. This module makes use of the LWP::Simple module, which you most likely already have.

FUNCTIONS

Top

trim($string)

Helper function that trims starting and ending spaces from the string.

fetch($artist, $song)

Fetch lyrics for the requested song.

AUTHOR

Top

Joshua Soles, <jbsoles at gmail.com>

BUGS

Top

Please report any bugs or feature requests to bug-lyrics-fetcher-lyrdb at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lyrics-Fetcher-LyrDB. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Lyrics::Fetcher::LyrDB




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Lyrics-Fetcher-LyrDB

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Lyrics-Fetcher-LyrDB

* CPAN Ratings

http://cpanratings.perl.org/d/Lyrics-Fetcher-LyrDB

* Search CPAN

http://search.cpan.org/dist/Lyrics-Fetcher-LyrDB

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Lyrics-Fetcher-LyrDB documentation Contained in the Lyrics-Fetcher-LyrDB distribution.
package Lyrics::Fetcher::LyrDB;

use warnings;
use strict;
use Carp;
use LWP::Simple;

our $VERSION = '0.02';
our $AGENT = "Perl/Lyric::Fetcher::LyrDB $VERSION";

sub trim($)
{
	my $string = shift;
	$string =~ s/^\s+//;
	$string =~s/^\s+$//;
	return $string;
}

sub fetch 
{
    
    	my $self = shift;
    	my ( $artist, $song ) = @_;
    	my $result = undef;
	my @number = ();
   	my $url = undef;

    	# reset the error var, change it if an error occurs.
    	$Lyrics::Fetcher::Error = 'OK';	
    
	unless ($artist && $song) 
	{
        	carp($Lyrics::Fetcher::Error = 
        	    'fetch() called without artist and song');

        	return;
	}
   
	# Get index of song.
	$url = "http://webservices.lyrdb.com/lookup.php?" .
		"q=$artist|$song&for=match&agent=iSing";

	$result = get $url;

	if(!defined $result)
	{
		carp($Lyrics::Fetcher::Error =
			'fetch() could not query LyrDB.');
		return;
	}
	
	# Let's pick the first one and give LyrDB a query on it.
	$result = trim $result;
	@number = $result =~ /(\d+)\\/;

	if(!scalar(@number))
	{
		$Lyrics::Fetcher::Error =
			"No id number found in query response.";
		return;
	}

	$url = "http://www.lyrdb.com/getlyr.php?q=$number[0]";

	$result = get $url;
	
	if($result =~ /error:\d\d\d/)
	{
		$result = $result =~ /\n+(.+)/;
		$Lyrics::Fetcher::Error = $result;
		return;
	}

    	# looks like it worked:
	$Lyrics::Fetcher::Error = 'OK';

    	return $result;


}



1;
__END__

# End of Lyrics::Fetcher::LyrDB