line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MP3::Find::Util; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use base qw(Exporter); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
176
|
|
7
|
2
|
|
|
2
|
|
10
|
use vars qw(@EXPORT_OK); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
104
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
@EXPORT_OK = qw(build_query get_mp3_metadata); |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
116
|
|
12
|
2
|
|
|
2
|
|
9
|
use MP3::Info; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1014
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
eval { require MP3::Tag }; |
15
|
|
|
|
|
|
|
my $CAN_USE_ID3V2 = $@ ? 0 : 1; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub build_query { |
18
|
0
|
|
|
0
|
0
|
0
|
my @args = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# first find all the directories |
21
|
0
|
|
|
|
|
0
|
my @dirs; |
22
|
0
|
|
|
|
|
0
|
while (local $_ = shift @args) { |
23
|
0
|
0
|
|
|
|
0
|
if (/^-/) { |
24
|
|
|
|
|
|
|
# whoops, there's the beginning of the query |
25
|
0
|
|
|
|
|
0
|
unshift @args, $_; |
26
|
0
|
|
|
|
|
0
|
last; |
27
|
|
|
|
|
|
|
} else { |
28
|
0
|
|
|
|
|
0
|
push @dirs, $_; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# now build the query hash |
33
|
0
|
|
|
|
|
0
|
my %query; |
34
|
|
|
|
|
|
|
my $field; |
35
|
0
|
|
|
|
|
0
|
while (local $_ = shift @args) { |
36
|
0
|
0
|
|
|
|
0
|
if (/^--?(.*)/) { |
37
|
0
|
|
|
|
|
0
|
$field = uc $1; |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
0
|
|
|
|
0
|
$field ? push @{ $query{$field} }, $_ : die "Need a field name before value '$_'\n"; |
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
return (\@dirs, \%query); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_mp3_metadata { |
47
|
2
|
|
|
2
|
0
|
3
|
my $args = shift; |
48
|
|
|
|
|
|
|
|
49
|
2
|
50
|
|
|
|
8
|
my $filename = $args->{filename} or croak "get_mp3_metadata needs a 'filename' argument"; |
50
|
|
|
|
|
|
|
|
51
|
2
|
50
|
|
|
|
9
|
my $mp3 = { |
52
|
|
|
|
|
|
|
FILENAME => $filename, |
53
|
2
|
50
|
|
|
|
55
|
%{ get_mp3tag($filename) || {} }, |
54
|
2
|
|
|
|
|
3
|
%{ get_mp3info($filename) || {} }, |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
33
|
|
|
42
|
if ($CAN_USE_ID3V2 and $args->{use_id3v2}) { |
58
|
|
|
|
|
|
|
# add ID3v2 tag info, if present |
59
|
0
|
|
|
|
|
0
|
my $mp3_tags = MP3::Tag->new($filename); |
60
|
0
|
0
|
|
|
|
0
|
unless (defined $mp3_tags) { |
61
|
0
|
|
|
|
|
0
|
warn "Can't get MP3::Tag object for $filename\n"; |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
0
|
$mp3_tags->get_tags; |
64
|
0
|
0
|
|
|
|
0
|
if (my $id3v2 = $mp3_tags->{ID3v2}) { |
65
|
0
|
|
|
|
|
0
|
for my $frame_id (keys %{ $id3v2->get_frame_ids }) { |
|
0
|
|
|
|
|
0
|
|
66
|
0
|
|
|
|
|
0
|
my ($info) = $id3v2->get_frame($frame_id); |
67
|
0
|
0
|
|
|
|
0
|
if (ref $info eq 'HASH') { |
68
|
|
|
|
|
|
|
# use the "Text" value as the value for this frame, if present |
69
|
0
|
0
|
|
|
|
0
|
$mp3->{$frame_id} = $info->{Text} if exists $info->{Text}; |
70
|
|
|
|
|
|
|
} else { |
71
|
0
|
|
|
|
|
0
|
$mp3->{$frame_id} = $info; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
6
|
return $mp3; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# module return |
82
|
|
|
|
|
|
|
1; |