line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::CDDBScan; |
2
|
|
|
|
|
|
|
require 5.004; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
2608
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
91
|
|
6
|
1
|
|
|
1
|
|
914
|
use LWP::Simple; |
|
1
|
|
|
|
|
306753
|
|
|
1
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
#use HTTP::Status; |
8
|
1
|
|
|
1
|
|
511
|
use URI::Escape; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5454
|
|
9
|
|
|
|
|
|
|
#use Data::Dumper; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
14
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
15
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
16
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
17
|
|
|
|
|
|
|
@EXPORT = qw//; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
@EXPORT_OK = qw/new getsongs getablums getartist/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$VERSION = '2.01'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# constructor optional params are: DEBUG and CONT |
24
|
|
|
|
|
|
|
# {{{ new |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
3
|
|
|
3
|
0
|
1158
|
my $class = shift; |
28
|
3
|
|
|
|
|
8
|
my $self = {}; |
29
|
3
|
|
|
|
|
10
|
bless($self, $class); |
30
|
3
|
|
|
|
|
18
|
$self->{ARG} = {@_}; |
31
|
3
|
50
|
|
|
|
18
|
$self ? return $self : return undef; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# }}} new |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# wrapper func to get songs from the given url |
37
|
|
|
|
|
|
|
# {{{ getsongs |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub getsongs { |
40
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
41
|
1
|
50
|
|
|
|
4
|
if (@_) { |
42
|
1
|
|
|
|
|
9
|
$self->{URL} = uri_escape(shift); |
43
|
1
|
|
|
|
|
59
|
$self->{ERROR} = undef; |
44
|
1
|
|
|
|
|
5
|
$self->{TYPE} = 'track'; |
45
|
1
|
50
|
33
|
|
|
7
|
print "$self>>Calling _getsongs();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} == 2); |
46
|
1
|
|
|
|
|
5
|
$self = _getsongs($self); |
47
|
1
|
50
|
|
|
|
9
|
defined $self->{ERROR} ? return undef : return $self->{SONGS}; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
0
|
$self->{ERROR} = 'No url provided'; |
50
|
0
|
|
|
|
|
0
|
return undef; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# }}} getsongs |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# wrapper func to get albums from the given url |
56
|
|
|
|
|
|
|
# {{{ getalbums |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub getalbums { |
59
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
60
|
1
|
50
|
|
|
|
4
|
if (@_) { |
61
|
1
|
|
|
|
|
6
|
$self->{URL} = uri_escape(shift); |
62
|
1
|
|
|
|
|
23
|
$self->{ERROR} = undef; |
63
|
1
|
|
|
|
|
4
|
$self->{TYPE} = 'disc'; |
64
|
1
|
50
|
33
|
|
|
5
|
print "$self>>Calling _getalbums();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} == 2); |
65
|
1
|
|
|
|
|
5
|
$self = _getalbums($self); |
66
|
1
|
50
|
|
|
|
12
|
defined $self->{ERROR} ? return undef : return $self->{ALBUMS}; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
0
|
$self->{ERROR} = 'No url provided'; |
69
|
0
|
|
|
|
|
0
|
return undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# }}} getalbums |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# wrapper func to get artist name(s) from the given url |
75
|
|
|
|
|
|
|
# {{{ getartist |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub getartist { |
78
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
79
|
1
|
50
|
|
|
|
7
|
if (@_) { |
80
|
1
|
|
|
|
|
8
|
$self->{URL} = uri_escape(shift); |
81
|
1
|
|
|
|
|
32
|
$self->{ERROR} = undef; |
82
|
1
|
|
|
|
|
23
|
$self->{TYPE} = 'artist'; |
83
|
1
|
50
|
33
|
|
|
9
|
print STDOUT "$self>>Calling _getartist();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} == 2); |
84
|
1
|
|
|
|
|
5
|
$self = _getartist($self); |
85
|
1
|
50
|
|
|
|
10
|
defined $self->{ERROR} ? return undef : return $self->{ARTIST}; |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
0
|
$self->{ERROR} = 'No url provided'; |
88
|
0
|
|
|
|
|
0
|
return undef; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# }}} getartist |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# destructor |
94
|
|
|
|
|
|
|
# {{{ DESTROY |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub DESTROY { |
97
|
3
|
|
|
3
|
|
407
|
my $self = shift; |
98
|
3
|
|
|
|
|
7
|
$self = {}; |
99
|
3
|
|
|
|
|
115
|
return 1; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# }}} DESTROY |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# get html data based on the given url |
105
|
|
|
|
|
|
|
# {{{ GetURL |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub GetURL { |
108
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
109
|
3
|
50
|
|
|
|
20
|
if ($self->{URL} =~ /(www|\/|htm)/) { |
110
|
0
|
|
|
|
|
0
|
$self->{URL} =~ s!(.*cddb.com/|.*xm/)(.*)!$2!; |
111
|
0
|
|
|
|
|
0
|
$self->{URL} =~ s!^/?(.*)!$1!; |
112
|
0
|
|
|
|
|
0
|
$self->{URL} = 'http://www.cddb.com/xm/' . $self->{URL}; |
113
|
|
|
|
|
|
|
} else { |
114
|
3
|
|
|
|
|
11
|
$self->{URL} = 'http://www.cddb.com/xm/search?q=' . $self->{URL}; |
115
|
|
|
|
|
|
|
# $self->{URL} .= '&f=' . $self->{TYPE} if (($self->{TYPE} eq 'track') || ($self->{TYPE} eq 'artist')); |
116
|
3
|
100
|
|
|
|
15
|
$self->{URL} .= '&f=' . $self->{TYPE} if ($self->{TYPE} eq 'track'); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
3
|
50
|
|
|
|
9
|
print STDOUT "$self>>URL: $self->{URL}\n" if $self->{ARG}->{DEBUG}; |
120
|
3
|
|
|
|
|
17
|
my $data = get($self->{URL}); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# if (is_error($data)) { |
123
|
|
|
|
|
|
|
# $self->{ERROR} = status_message($data); |
124
|
|
|
|
|
|
|
# return undef; |
125
|
|
|
|
|
|
|
# } |
126
|
3
|
|
|
|
|
2751725
|
$self->{DATA} = [split('\n', $data)]; |
127
|
3
|
|
|
|
|
15
|
return $self |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# }}} GetURL |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# locates and returns a hash of url/names based on the given url |
133
|
|
|
|
|
|
|
# {{{ _getalbums |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _getalbums { |
136
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
137
|
|
|
|
|
|
|
# setup some local vars |
138
|
1
|
|
|
|
|
3
|
my($line, $n1, $n2, $n3, $n4); |
139
|
|
|
|
|
|
|
|
140
|
1
|
50
|
33
|
|
|
5
|
print "$self>>Calling GetURL();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} ==2); |
141
|
1
|
|
|
|
|
3
|
$self = GetURL($self); |
142
|
|
|
|
|
|
|
|
143
|
1
|
50
|
|
|
|
8
|
return $self if (!$self->{DATA}); |
144
|
|
|
|
|
|
|
|
145
|
1
|
|
|
|
|
5
|
foreach $line (@{$self->{DATA}}) { |
|
1
|
|
|
|
|
4
|
|
146
|
0
|
0
|
|
|
|
0
|
if ($line =~ /^\s*?]/) { |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
0
|
if ($line =~ m!\s?(([^<]+)\s?\/\s?)?([^<]+).*!) { |
149
|
0
|
|
|
|
|
0
|
($n1, $n2, $n3, $n4) = ($1, $2, $3, $4); |
150
|
0
|
|
|
|
|
0
|
push(@{$self->{OLDURL}}, $self->{URL}); |
|
0
|
|
|
|
|
0
|
|
151
|
0
|
0
|
|
|
|
0
|
print "$self>> Got an album: '$n4'\n" if $self->{ARG}->{DEBUG}; |
152
|
0
|
|
|
|
|
0
|
$self->{URL} = $n1; |
153
|
0
|
|
|
|
|
0
|
$self->{ALBUMS}->{$n1} = $n4; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
0
|
if ($self->{ARG}->{CONT}) { |
158
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
0
|
if ($line =~ m!.*\[.+NEXT.*\]!) { |
160
|
0
|
|
|
|
|
0
|
push(@{$self->{OLDURL}}, $self->{URL}); |
|
0
|
|
|
|
|
0
|
|
161
|
0
|
|
|
|
|
0
|
$self->{URL} = $1; |
162
|
0
|
0
|
0
|
|
|
0
|
print "$self>>Calling _getalbums();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} ==2); |
163
|
0
|
|
|
|
|
0
|
_getalbums($self); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
1
|
|
|
|
|
4
|
return $self; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# }}} _getalbums |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# locates and returns an hash of url/names based on the given url |
173
|
|
|
|
|
|
|
# {{{ _getsongs |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _getsongs { |
176
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
177
|
1
|
|
|
|
|
2
|
my($line, $n1, $n2, $n3, $n4); |
178
|
|
|
|
|
|
|
|
179
|
1
|
50
|
33
|
|
|
6
|
print "$self>>Calling GetURL();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} ==2); |
180
|
1
|
|
|
|
|
4
|
$self = GetURL($self); |
181
|
|
|
|
|
|
|
|
182
|
1
|
50
|
|
|
|
11
|
return $self if (!$self->{DATA}); |
183
|
|
|
|
|
|
|
|
184
|
1
|
|
|
|
|
3
|
foreach $line (@{$self->{DATA}}) { |
|
1
|
|
|
|
|
4
|
|
185
|
0
|
0
|
|
|
|
0
|
if ($line =~ /^\s*?]/) { |
186
|
|
|
|
|
|
|
|
187
|
0
|
0
|
|
|
|
0
|
if ($line =~ m!\s?(([^<]+)\s?\/\s?)?([^<]+).*!) { |
188
|
0
|
|
|
|
|
0
|
($n1, $n2, $n3, $n4) = ($1, $2, $3, $4); |
189
|
|
|
|
|
|
|
|
190
|
0
|
0
|
0
|
|
|
0
|
if ((defined $n2 && $n2 !~ /^(\s+)?$/) && (defined $n3 && $n3 !~ /^(\s+)?$/) && ($1 !~ /track/)) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
191
|
0
|
|
|
|
|
0
|
push(@{$self->{OLDURL}}, $self->{URL}); |
|
0
|
|
|
|
|
0
|
|
192
|
0
|
|
|
|
|
0
|
$self->{URL} = $n1; |
193
|
0
|
0
|
0
|
|
|
0
|
print "$self>>Calling _getsongs();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} ==2); |
194
|
0
|
|
|
|
|
0
|
_getsongs($self); |
195
|
0
|
0
|
|
|
|
0
|
last unless $self->{ARG}->{CONT}; |
196
|
|
|
|
|
|
|
} else { |
197
|
0
|
|
|
|
|
0
|
push(@{$self->{OLDURL}}, $self->{URL}); |
|
0
|
|
|
|
|
0
|
|
198
|
0
|
0
|
0
|
|
|
0
|
print "$self>> Got a song: $n4\n" if $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} == 2; |
199
|
0
|
|
|
|
|
0
|
$self->{URL} = $n1; |
200
|
0
|
|
|
|
|
0
|
$self->{SONGS}->{$n1} = uri_unescape($n4); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
1
|
50
|
|
|
|
5
|
if ($self->{ARG}->{CONT}) { |
206
|
0
|
|
|
|
|
0
|
foreach $line (@{$self->{DATA}}) { |
|
0
|
|
|
|
|
0
|
|
207
|
0
|
0
|
|
|
|
0
|
if ($line =~ m!.*\[.+NEXT.*\]!) { |
208
|
0
|
|
|
|
|
0
|
push(@{$self->{OLDURL}}, $self->{URL}); |
|
0
|
|
|
|
|
0
|
|
209
|
0
|
|
|
|
|
0
|
$self->{URL} = $1; |
210
|
0
|
0
|
0
|
|
|
0
|
print "$self>>Calling _getsongs();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} ==2); |
211
|
0
|
|
|
|
|
0
|
_getsongs($self); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
1
|
|
|
|
|
3
|
$self->{DATA} = undef; |
216
|
1
|
|
|
|
|
3
|
return $self; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# }}} _getsongs |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# locates and returns an artist based on the given url |
222
|
|
|
|
|
|
|
# {{{ _getartist |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub _getartist { |
225
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
226
|
1
|
|
|
|
|
3
|
my($line, $n1, $n2, $n3, $n4); |
227
|
|
|
|
|
|
|
|
228
|
1
|
50
|
33
|
|
|
8
|
print "$self>>Calling GetURL();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} ==2); |
229
|
1
|
|
|
|
|
4
|
$self = GetURL($self); |
230
|
|
|
|
|
|
|
|
231
|
1
|
50
|
|
|
|
9
|
return $self if (!$self->{DATA}); |
232
|
|
|
|
|
|
|
|
233
|
1
|
|
|
|
|
3
|
foreach $line (@{$self->{DATA}}) { |
|
1
|
|
|
|
|
3
|
|
234
|
0
|
0
|
|
|
|
0
|
if ($line =~ /^\s*?]/) { |
235
|
|
|
|
|
|
|
|
236
|
0
|
0
|
|
|
|
0
|
if ($line =~ m!\s?(([^\/]+)\/)?\s?([^<]+)!) { |
237
|
0
|
|
|
|
|
0
|
($n1, $n2, $n3, $n4) = ($1, $2, $3, $4); |
238
|
0
|
0
|
|
|
|
0
|
if ($n3 !~ /^(\s+)?$/) { |
239
|
0
|
|
|
|
|
0
|
$self->{ARTIST} = $n3; |
240
|
0
|
|
|
|
|
0
|
last; |
241
|
|
|
|
|
|
|
} |
242
|
0
|
|
|
|
|
0
|
push(@{$self->{OLDURL}}, $self->{URL}); |
|
0
|
|
|
|
|
0
|
|
243
|
0
|
|
|
|
|
0
|
$self->{URL} = $n1; |
244
|
0
|
0
|
0
|
|
|
0
|
print "$self>>Calling _getmessage();\n" if (defined $self->{ARG}->{DEBUG} && $self->{ARG}->{DEBUG} ==2); |
245
|
0
|
|
|
|
|
0
|
_getartist($self); |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
} |
249
|
1
|
|
|
|
|
5
|
$self->{DATA} = undef; |
250
|
1
|
|
|
|
|
3
|
return $self; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# }}} _getartist |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# loads the master db hash from disk |
256
|
0
|
|
|
0
|
0
|
|
sub load_data { |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
# writes the master db hash to disk |
260
|
0
|
|
|
0
|
0
|
|
sub dump_data { |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
# takes a hashref off the master db hash and links it on the $self obj for current return data |
264
|
|
|
|
|
|
|
sub link_data { |
265
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
1; |
268
|
|
|
|
|
|
|
__END__ |