File Coverage

blib/lib/MP3/Find.pm
Criterion Covered Total %
statement 22 23 95.6
branch 1 2 50.0
condition 1 2 50.0
subroutine 6 7 85.7
pod 1 1 100.0
total 31 35 88.5


line stmt bran cond sub pod time code
1             package MP3::Find;
2              
3 1     1   20113 use strict;
  1         2  
  1         29  
4 1     1   4 use warnings;
  1         1  
  1         27  
5              
6 1     1   5 use base qw(Exporter);
  1         5  
  1         104  
7 1     1   4 use vars qw($VERSION @EXPORT);
  1         2  
  1         59  
8              
9 1     1   4 use Carp;
  1         1  
  1         225  
10              
11             $VERSION = '0.07';
12              
13             @EXPORT = qw(find_mp3s);
14              
15             my $finder;
16             sub import {
17 1     1   5 my $calling_pkg = shift;
18             # default to a filesystem search
19 1   50     6 my $finder_type = shift || 'Filesystem';
20 1         3 my $package = "MP3::Find::$finder_type";
21 1         40 eval "require $package";
22 1 50       8 croak $@ if $@;
23 1         13 $finder = $package->new;
24 1         102 __PACKAGE__->export_to_level(1, @EXPORT);
25             }
26              
27 0     0 1   sub find_mp3s { $finder->find_mp3s(@_) }
28              
29              
30             # module return
31             1;
32              
33             =head1 NAME
34              
35             MP3::Find - Search and sort MP3 files based on their ID3 tags
36              
37             =head1 SYNOPSIS
38              
39             # select with backend you want
40             use MP3::Find qw(Filesystem);
41            
42             print "$_\n" foreach find_mp3s(
43             dir => '/home/peter/cds',
44             query => {
45             artist => 'ilyaimy',
46             title => 'deep in the am',
47             },
48             ignore_case => 1,
49             exact_match => 1,
50             sort => [qw(year album tracknum)],
51             printf => '%2n. %a - %t (%b: %y)',
52             );
53              
54             =head1 DESCRIPTION
55              
56             This module allows you to search for MP3 files by their ID3 tags.
57             You can ask for the results to be sorted by one or more of those
58             tags, and return either the list of filenames (the deault), a
59             C-style formatted string for each file using its ID3 tags,
60             or the actual Perl data structure representing the results.
61              
62             There are currently two backends to this module: L
63             and L. You choose which one you want by passing its
64             name as the argument to you C statement; B will look for
65             a B module. If no backend name is given, it will
66             default to using L.
67              
68             B I'm still working out some kinks in the DB backend, so it
69             is currently not as stable as the Filesystem backend.
70              
71             B: This whole project is still in the alpha stage, so
72             I can make no guarentees that there won't be significant interface changes
73             in the next few versions or so. Also, comments about what about the API
74             rocks (or sucks!) are appreciated.
75              
76             =head1 REQUIRES
77              
78             L, L, and L are needed for
79             the filesystem backend (L). In addition,
80             if L is available, you can search by explicit ID3v2
81             tag frames.
82              
83             L, L, and L are needed for the
84             database backend (L).
85              
86             =head1 EXPORTS
87              
88             =head2 find_mp3s
89              
90             my @results = find_mp3s(%options);
91              
92             Takes the following options:
93              
94             =over
95              
96             =item C
97              
98             Arrayref or scalar; tell C where to start the search.
99             Directories in the arrayref are searched sequentially.
100              
101             =item C
102              
103             Hashref of search parameters. Recognized fields are anything that
104             L knows about. Field names can be given in either upper
105             or lower case; C will convert them into upper case for
106             you. Value may either be strings, which are converted into regular
107             exporessions, or may be C regular expressions already.
108              
109             =item C
110              
111             Boolean, default false; set to a true value to ignore case when
112             matching search strings to the ID3 tag values.
113              
114             =item C
115              
116             Boolean, default false; set to a true value to add an implicit
117             C<^> and C<$> around each query string. Does nothing if the query
118             term is already a regular expression.
119              
120             =item C
121              
122             What field or fields to sort the results by. Can either be a single
123             scalar field name to sort by, or an arrayref of field names. Again,
124             acceptable field names are anything that L knows about;
125             field names will be converted to upper case as with the C
126             option.
127              
128             =item C
129              
130             By default, C just returns the list of filenames. The
131             C option allows you to provide a formatting string to apply
132             to the data for each file. The style is roughly similar to Perl's
133             C format strings. The following formatting codes are
134             recognized:
135              
136             %a - artist
137             %t - title
138             %b - album
139             %n - track number
140             %y - year
141             %g - genre
142             %% - literal '%'
143              
144             Numeric modifers may be used in the same manner as with C<%s> in
145             Perl's C.
146              
147             =item C
148              
149             Boolean, default false; set to a true value to have C to
150             return an array of hashrefs instead of an array of (formatted) strings.
151             Each hashref consists of the key-value pairs from C
152             and C, plus the key C (with the obvious
153             value ;-)
154              
155             @results = (
156             {
157             FILENAME => ...,
158             TITLE => ...,
159             ARTIST => ...,
160             ...
161             SECS => ...,
162             BITRATE => ...,
163             ...
164             },
165             ...
166             );
167              
168             =back
169              
170             =head1 BUGS
171              
172             There are probably some in there; let me know if you find any (patches
173             welcome).
174              
175             =head1 TODO
176              
177             Better tests, using some actual sample mp3 files.
178              
179             Other backends (a caching filesystem backend, perhaps?)
180              
181             =head1 SEE ALSO
182              
183             L, L
184              
185             L is the command line frontend to this module (it
186             currently only uses the filesystem backend).
187              
188             L is a (currently rather barebones) command line
189             frontend for creating and updating a SQLite database for
190             use with L.
191              
192             See L for more information about the fields you can
193             search and sort on. See L for information about
194             ID3v2 tags.
195              
196             L is another way to search for MP3
197             files based on their ID3 tags.
198              
199             =head1 AUTHOR
200              
201             Peter Eichman
202              
203             =head1 COPYRIGHT AND LICENSE
204              
205             Copyright (c) 2006 by Peter Eichman. All rights reserved.
206              
207             This program is free software; you can redistribute it and/or
208             modify it under the same terms as Perl itself.
209              
210             =cut