| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Lyrics::Fetcher::LyricsDownload; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1357
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
53
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1209
|
use Encode; |
|
|
1
|
|
|
|
|
17623
|
|
|
|
1
|
|
|
|
|
130
|
|
|
6
|
1
|
|
|
1
|
|
1505
|
use HTML::TokeParser; |
|
|
1
|
|
|
|
|
15109
|
|
|
|
1
|
|
|
|
|
36
|
|
|
7
|
1
|
|
|
1
|
|
837
|
use LWP::Simple qw($ua get); |
|
|
1
|
|
|
|
|
74190
|
|
|
|
1
|
|
|
|
|
11
|
|
|
8
|
1
|
|
|
1
|
|
246
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
763
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.01'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub fetch { |
|
13
|
0
|
|
|
0
|
1
|
|
my($self,$artist, $title) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
$Lyrics::Fetcher::Error = 'OK'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
0
|
0
|
0
|
|
|
|
unless ($artist && $title) { |
|
18
|
0
|
|
|
|
|
|
$Lyrics::Fetcher::Error = 'fetch() called without artist and song title'; |
|
19
|
0
|
|
|
|
|
|
return; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$artist =~ s/ ((^\w)|(\s\w))/\U$1/xg; |
|
23
|
0
|
|
|
|
|
|
$artist =~ s/\ /\-/g; |
|
24
|
0
|
|
|
|
|
|
$artist =~ s/\"//g; |
|
25
|
0
|
|
|
|
|
|
$artist =~ s/\'//g; |
|
26
|
0
|
|
|
|
|
|
$artist =~ s/\,//g; |
|
27
|
0
|
|
|
|
|
|
$artist =~ s/\://g; |
|
28
|
0
|
|
|
|
|
|
$artist =~ s/\?//g; |
|
29
|
0
|
|
|
|
|
|
$artist =~ s/\.//g; |
|
30
|
0
|
|
|
|
|
|
$artist =~ s/\&/and/g; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$title =~ s/ ((^\w)|(\s\w))/\U$1/xg; |
|
33
|
0
|
|
|
|
|
|
$title =~ s/\ /\-/g; |
|
34
|
0
|
|
|
|
|
|
$title =~ s/\"//g; |
|
35
|
0
|
|
|
|
|
|
$title =~ s/\'//g; |
|
36
|
0
|
|
|
|
|
|
$title =~ s/\,//g; |
|
37
|
0
|
|
|
|
|
|
$title =~ s/\://g; |
|
38
|
0
|
|
|
|
|
|
$title =~ s/\?//g; |
|
39
|
0
|
|
|
|
|
|
$title =~ s/\.//g; |
|
40
|
0
|
|
|
|
|
|
$title =~ s/\&/and/g; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $lyrics = ""; |
|
43
|
0
|
|
|
|
|
|
my $url = "http://www.lyricsdownload.com/".$artist."-".$title."-lyrics.html"; |
|
44
|
0
|
|
|
|
|
|
$url = lc($url); |
|
45
|
0
|
|
|
|
|
|
my $content = get($url); |
|
46
|
0
|
0
|
|
|
|
|
if($content eq "") { $Lyrics::Fetcher::Error = 'Content empty'; return; } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
utf8::decode($content); |
|
48
|
0
|
|
|
|
|
|
my $parser = HTML::TokeParser->new(\$content); |
|
49
|
0
|
|
|
|
|
|
$parser->{textify} = {'br'}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
while( my $token = $parser->get_token() ) { |
|
52
|
0
|
0
|
|
|
|
|
if($token->[0] eq "S") { |
|
53
|
0
|
0
|
|
|
|
|
if($token->[1] eq "font") { |
|
54
|
0
|
0
|
|
|
|
|
if($token->[4] =~ /\"txt_1\"/) { |
|
55
|
0
|
|
|
|
|
|
$lyrics = $parser->get_trimmed_text('/font'); |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if($lyrics =~ /Translated title:/) {} |
|
|
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
elsif($lyrics =~ /back to \-\>/) {} |
|
59
|
|
|
|
|
|
|
else { |
|
60
|
0
|
|
|
|
|
|
$lyrics =~ s/\[BR\]\ /\n/g; |
|
61
|
0
|
|
|
|
|
|
$lyrics =~ s/\[BR\]/\n/g; |
|
62
|
0
|
|
|
|
|
|
last; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $lyrics; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Lyrics::Fetcher::LyricsDownload - Get song lyrics from lyricsdownload.com |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
use Lyrics::Fetcher; |
|
81
|
|
|
|
|
|
|
print Lyrics::Fetcher->fetch("","","LyricsDownload"); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# or, if you want to use this module directly without Lyrics::Fetcher's |
|
84
|
|
|
|
|
|
|
# involvement (be aware that using Lyrics::Fetcher is the recommended way): |
|
85
|
|
|
|
|
|
|
use Lyrics::Fetcher::LyricsDownload; |
|
86
|
|
|
|
|
|
|
print Lyrics::Fetcher::LyricsDownload->fetch('', ''); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This module tries to get song lyrics from lyricsdownload.com. It's designed |
|
92
|
|
|
|
|
|
|
to be called by Lyrics::Fetcher, and this is the recommended usage, but it can |
|
93
|
|
|
|
|
|
|
be used directly if you'd prefer. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 INTERFACE |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=over 4 |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item fetch($artist, $title) |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Attempts to fetch lyrics. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 BUGS |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
if you find any bugs, please let me know. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Copyright (C) 2008 by Rick Blevins |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
|
116
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Rick Blevins Erick816us@comcast.netE |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 LEGAL DISCLAIMER |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Legal disclaimer: I have no connection with the owners of lyricsdownload.com. |
|
127
|
|
|
|
|
|
|
Lyrics fetched by this script may be copyrighted by the authors, it's up to |
|
128
|
|
|
|
|
|
|
you to determine whether this is the case, and if so, whether you are entitled |
|
129
|
|
|
|
|
|
|
to request/use those lyrics. You will almost certainly not be allowed to use |
|
130
|
|
|
|
|
|
|
the lyrics obtained for any commercial purposes. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |