| 1 | package Lyrics::Fetcher::AstraWeb; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # AstraWeb - lyrics.astraweb.com implementation | ||||||||||||||||||||
| 4 | # | ||||||||||||||||||||
| 5 | # Copyright (C) 2003 Sir Reflog <reflog@mail15.com> | ||||||||||||||||||||
| 6 | # All rights reserved. | ||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # Maintainership of Lyrics::Fetcher transferred in Feb 07 to BIGPRESH | ||||||||||||||||||||
| 9 | # (David Precious <davidp@preshweb.co.uk>) | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # $Id: AstraWeb.pm 333 2008-04-24 18:53:53Z davidp $ | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 2 | ▶ | use WWW::Mechanize; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 2 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | $VERSION = '0.33'; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub fetch { | ||||||||||||||||||
|
Subroutine
fetch: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 21 | 0 | my($self,$artist, $title) = @_; | |||||||||||||||||||
| 22 | 0 | my $agent = WWW::Mechanize->new(); | |||||||||||||||||||
| 23 | 0 | my($sartist) = join ("+", split(/ /, $artist)); | |||||||||||||||||||
| 24 | 0 | my($stitle) = join ("+", split(/ /, $title)); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # quote regexp meta-characters to avoid breakage: | ||||||||||||||||||||
| 27 | 0 | $title = quotemeta $title; | |||||||||||||||||||
| 28 | 0 | $artist = quotemeta $artist; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | $agent->get("http://search.lyrics.astraweb.com/?word=$sartist+$stitle"); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | ▶ | if(grep { $_->text() =~ /$title/ }@{$agent->links}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | $agent->follow_link(text_regex => qr((?-xism:$title))); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | ▶ | if(grep { $_->text() =~ /Printable/ }@{$agent->links}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | $agent->follow_link(text_regex => qr((?-xism:Printable))); | |||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||
| 38 | 0 | $Lyrics::Fetcher::Error = 'Bad page format'; | |||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||
| 42 | 0 | $Lyrics::Fetcher::Error = 'Cannot find such title'; | |||||||||||||||||||
| 43 | 0 | return; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | ▶ | return $agent->content =~ /<blockquote>(.*)<\/blockquote>/ && $1; | ||||||||||||||||||
|
Condition0%0/3
$agent->content =~ m[<blockquote>(.*)</blockquote>] && $1
MC/DC0%0/2
$agent->content =~ m[<blockquote>(.*)</blockquote>] && $1
$agent->content =~ m[<blockquote>(.*)</blockquote>]
$1
Truth table0%0/3
A && B
A= $agent->content =~ m[<blockquote>(.*)</blockquote>]B= $1
| |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | 1; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =head1 NAME | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | Lyrics::Fetcher::AstraWeb - Get song lyrics from lyrics.astraweb.com | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =head1 SYNOPSIS | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | use Lyrics::Fetcher; | ||||||||||||||||||||
| 58 | print Lyrics::Fetcher->fetch("<artist>","<song>","AstraWeb"); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | # or, if you want to use this module directly without Lyrics::Fetcher's | ||||||||||||||||||||
| 61 | # involvement (be aware that using Lyrics::Fetcher is the recommended way): | ||||||||||||||||||||
| 62 | use Lyrics::Fetcher::AstraWeb; | ||||||||||||||||||||
| 63 | print Lyrics::Fetcher::AstraWeb->fetch('<artist>', '<song>'); | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =head1 DESCRIPTION | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | This module tries to get song lyrics from lyrics.astraweb.com. It's designed | ||||||||||||||||||||
| 69 | to be called by Lyrics::Fetcher, and this is the recommended usage, but it can | ||||||||||||||||||||
| 70 | be used directly if you'd prefer. | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =head1 INTERFACE | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =over 4 | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =item fetch($artist, $title) | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | Attempts to fetch lyrics. | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =back | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =head1 BUGS | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | Probably. If you find any bugs, please let me know. | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | Copyright (C) 2007 by David Precious | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 93 | the same terms as Perl itself. | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head1 AUTHOR | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | David Precious E<lt>davidp@preshweb.co.ukE<gt> | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =head1 LEGAL DISCLAIMER | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Legal disclaimer: I have no connection with the owners of astraweb.com. | ||||||||||||||||||||
| 104 | Lyrics fetched by this script may be copyrighted by the authors, it's up to | ||||||||||||||||||||
| 105 | you to determine whether this is the case, and if so, whether you are entitled | ||||||||||||||||||||
| 106 | to request/use those lyrics. You will almost certainly not be allowed to use | ||||||||||||||||||||
| 107 | the lyrics obtained for any commercial purposes. | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||