line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MP3::Album::Layout::Fetcher::CDDB; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1827
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
5
|
use MP3::Album::Layout; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
584
|
use CDDB; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Data::Dumper; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub fetch { |
9
|
|
|
|
|
|
|
my $c = shift; |
10
|
|
|
|
|
|
|
my %a = @_; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @results = (); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$a{cddb_host} = $a{cddb_host} || 'freedb.freedb.org'; |
15
|
|
|
|
|
|
|
$a{cddb_port} = $a{cddb_port} || 8880; |
16
|
|
|
|
|
|
|
$a{cddb_login} = $a{cddb_login} || $ENV{USER}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $cddb = new CDDB( Host => $a{cddb_host}, |
20
|
|
|
|
|
|
|
Port => $a{cddb_port}, |
21
|
|
|
|
|
|
|
Login => $a{cddb_login}); |
22
|
|
|
|
|
|
|
if (!$cddb) { |
23
|
|
|
|
|
|
|
$@ = "error connecting to cddb"; |
24
|
|
|
|
|
|
|
return undef; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return [] unless ($a{album}->{cddb_query}->{discid} && $a{album}->{cddb_query}->{frames} && $a{album}->{cddb_query}->{disctime}); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my @cddb_discs = $cddb->get_discs( $a{album}->{cddb_query}->{discid}, |
30
|
|
|
|
|
|
|
$a{album}->{cddb_query}->{frames}, |
31
|
|
|
|
|
|
|
$a{album}->{cddb_query}->{disctime} |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
foreach my $disc (@cddb_discs) { |
34
|
|
|
|
|
|
|
my $disc_info = $cddb->get_disc_details($disc->[0], $disc->[1]); |
35
|
|
|
|
|
|
|
last unless $disc_info; |
36
|
|
|
|
|
|
|
my ($artist,$title) = split(/\s*\/\s*/, $disc->[2]); |
37
|
|
|
|
|
|
|
my $layout = MP3::Album::Layout->new(); |
38
|
|
|
|
|
|
|
$layout->artist($artist); |
39
|
|
|
|
|
|
|
$layout->title($title); |
40
|
|
|
|
|
|
|
$layout->genre($disc->[0]); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $k = 0; |
43
|
|
|
|
|
|
|
foreach my $t (@{$disc_info->{ttitles}}) { |
44
|
|
|
|
|
|
|
$layout->add_track( title => $t, artist => $artist, lenght=> $disc_info->{seconds}->[$k]); |
45
|
|
|
|
|
|
|
$k++; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
push @results, $layout; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return \@results; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |