| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package AudioFile::Find; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
35986
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
484
|
use File::Find::Rule; |
|
|
1
|
|
|
|
|
7197
|
|
|
|
1
|
|
|
|
|
7
|
|
|
7
|
1
|
|
|
1
|
|
535
|
use AudioFile::Info; |
|
|
1
|
|
|
|
|
6175
|
|
|
|
1
|
|
|
|
|
27
|
|
|
8
|
1
|
|
|
1
|
|
474
|
use List::MoreUtils qw( zip ); |
|
|
1
|
|
|
|
|
838
|
|
|
|
1
|
|
|
|
|
63
|
|
|
9
|
1
|
|
|
1
|
|
15
|
use YAML 'LoadFile'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
435
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
AudioFile::Find - Finds audio files located on your system and maps them to L objects. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use AudioFile::Find; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $finder = AudioFile::Find->new( 'some/dir' ); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# find everything |
|
26
|
|
|
|
|
|
|
my @audiofiles = $finder->search(); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# specify a search directory |
|
29
|
|
|
|
|
|
|
my @audiofiles = $finder->search( 'some/other/dir' ); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#same for genre, title, track, artist and album |
|
32
|
|
|
|
|
|
|
my @audiofiles = $finder->search( artist => 'Seeed' ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#search using a regex |
|
35
|
|
|
|
|
|
|
my @audiofiles = $finder->search( 'some/other/dir', title => qr/Ding/ ); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# anonymous subroutine that returns true or false |
|
38
|
|
|
|
|
|
|
my @audiofiles = $finder->search( 'some/other/dir', track => sub { return shift > 10; } ); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 new |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Creates an object of this class. Takes an optional single argument which is the directory to search in. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
|
49
|
3
|
|
|
3
|
1
|
4841
|
my ($class, $dir) = @_; |
|
50
|
3
|
|
|
|
|
11
|
return bless { dir => $dir }, $class; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 new |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Sets and returns the directory to search. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub dir { |
|
60
|
1
|
|
|
1
|
0
|
236
|
my ($self, $dir) = @_; |
|
61
|
1
|
50
|
|
|
|
4
|
$self->{dir} = $dir if defined $dir; |
|
62
|
1
|
|
|
|
|
11
|
return $self->{dir}; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 search |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Starts the search and returns a hash of filenames as keys and AudioFile::Info-Objects as values. |
|
68
|
|
|
|
|
|
|
You may specify a search directory as the first argument |
|
69
|
|
|
|
|
|
|
and also pass a hash with search criteria. See the synopsis for details. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub search { |
|
74
|
2
|
|
|
2
|
1
|
564
|
my $self = shift; |
|
75
|
2
|
100
|
|
|
|
9
|
my $dir = @_ % 2 == 0 ? '' : shift; |
|
76
|
2
|
|
|
|
|
4
|
my $args = {@_}; |
|
77
|
2
|
|
|
|
|
2
|
my %audio; |
|
78
|
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
5
|
my @patterns = map { "*.$_" } $self->extensions; |
|
|
2
|
|
|
|
|
15
|
|
|
80
|
2
|
|
50
|
|
|
68
|
for ( File::Find::Rule->file()->name( @patterns )->in( $dir || $self->dir || '.' ) ) |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
2
|
|
|
|
|
1226
|
my $info = AudioFile::Info->new($_); |
|
83
|
|
|
|
|
|
|
|
|
84
|
2
|
50
|
|
|
|
8
|
$audio{$_} = $info |
|
85
|
|
|
|
|
|
|
if $self->pass( $info, $args); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
14
|
return %audio; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 pass |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Checks whether a given L object meets given criteria. |
|
94
|
|
|
|
|
|
|
First argument is the L object, second argument is a reference to the criteria hash. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub pass |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
2
|
|
|
2
|
1
|
3
|
my ($self, $file, $criteria) = @_; |
|
101
|
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
9
|
while ( my ($key, $criterium) = each %$criteria ) |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
0
|
|
|
|
|
0
|
my $value = $file->$key; |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
0
|
if ( ref($criterium) eq "Regexp" ) |
|
|
|
0
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
{ |
|
108
|
0
|
0
|
|
|
|
0
|
return unless $value =~ $criterium; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
elsif ( ref($criterium) eq "CODE" ) |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
0
|
0
|
|
|
|
0
|
return unless $criterium->( $value ); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
else |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
0
|
0
|
|
|
|
0
|
return unless $value eq $criterium; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
2
|
|
|
|
|
9
|
return 1; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 extensions |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Discovers the extensions that are supported by the installed L plugins. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub extensions { |
|
130
|
1
|
|
|
1
|
|
4
|
my ($self) = @_; |
|
131
|
1
|
|
|
|
|
2
|
my $path = $INC{'AudioFile/Info.pm'}; |
|
132
|
1
|
|
|
|
|
6
|
$path =~ s/Info.pm$/plugins.yaml/; |
|
133
|
1
|
|
|
|
|
4
|
my $config = LoadFile($path); |
|
134
|
0
|
|
|
|
|
|
my @ext = keys %{ $config->{default} }; |
|
|
0
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
return @ext; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHORS |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item Markus, C<< >> |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item Joel Berger C |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 SOURCE REPOSITORY |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 BUGS |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Bugs may be reported to: |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item L |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item L |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=back |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Copyright 2008-2014 by Authors listed above, all rights reserved. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
171
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
|
174
|
|
|
|
|
|
|
|