1 | #!/usr/bin/perl -w |
---|
2 | use strict; |
---|
3 | |
---|
4 | use Getopt::Long qw(:config pass_through); # use pass_through so we can get the query args |
---|
5 | |
---|
6 | use MP3::Find qw(Filesystem); |
---|
7 | use MP3::Find::Util qw(build_query); |
---|
8 | use File::Spec::Functions qw(catfile); |
---|
9 | |
---|
10 | GetOptions( |
---|
11 | 'ignore-case|i' => \my $IGNORE_CASE, |
---|
12 | 'exact-match|w' => \my $EXACT_MATCH, |
---|
13 | 'sort|s=s' => \my $SORT_TAG, |
---|
14 | 'printf=s' => \my $FORMAT, |
---|
15 | '2' => \my $USE_ID3V2, |
---|
16 | ); |
---|
17 | |
---|
18 | my ($DIRS, $QUERY) = build_query(@ARGV); |
---|
19 | push @$DIRS, '.' unless @$DIRS; |
---|
20 | |
---|
21 | print "$_\n" foreach find_mp3s( |
---|
22 | dir => $DIRS, |
---|
23 | query => $QUERY, |
---|
24 | ignore_case => $IGNORE_CASE, |
---|
25 | exact_match => $EXACT_MATCH, |
---|
26 | ($SORT_TAG ? (sort => [split(/,/, $SORT_TAG)]) : ()), |
---|
27 | printf => $FORMAT, |
---|
28 | db_file => catfile($ENV{HOME}, 'mp3.db'), |
---|
29 | use_id3v2 => $USE_ID3V2, |
---|
30 | ); |
---|
31 | |
---|
32 | =head1 NAME |
---|
33 | |
---|
34 | mp3find - Find MP3 files based on their ID3 tags or info |
---|
35 | |
---|
36 | =head1 SYNOPSIS |
---|
37 | |
---|
38 | $ mp3find ~/cds -i -artist beatles -sort year,album,tracknum -printf '%2n. %a - %t (%b: %y)' |
---|
39 | 1. The Beatles - Magical Mystery Tour (Magical Mystery Tour: 1967) |
---|
40 | 2. The Beatles - The Fool on the Hill (Magical Mystery Tour: 1967) |
---|
41 | 3. The Beatles - Flying (Magical Mystery Tour: 1967) |
---|
42 | 4. The Beatles - Blue Jay Way (Magical Mystery Tour: 1967) |
---|
43 | 5. The Beatles - Your Mother Should Know (Magical Mystery Tour: 1967) |
---|
44 | 6. The Beatles - I Am The Walrus (Magical Mystery Tour: 1967) |
---|
45 | # etc. |
---|
46 | |
---|
47 | # shuffle and play your entire mp3 collection |
---|
48 | $ mp3find | xargs madplay -z |
---|
49 | |
---|
50 | # ...or just your Sabbath |
---|
51 | $ mp3find -i -artist 'black sabbath' | xargs madplay -z |
---|
52 | |
---|
53 | =head1 DESCRIPTION |
---|
54 | |
---|
55 | $ mp3find [options] [directory] [<-field> <pattern> [<-field> <pattern> ...]] |
---|
56 | |
---|
57 | The real guts of the operation are in L<MP3::Find>. |
---|
58 | |
---|
59 | =head2 OPTIONS |
---|
60 | |
---|
61 | =over |
---|
62 | |
---|
63 | =item C<-ignore-case>, C<-i> |
---|
64 | |
---|
65 | Case insensitive matching. |
---|
66 | |
---|
67 | =item C<-exact-match>, C<-w> |
---|
68 | |
---|
69 | All search patterns must match the entire value, and not just a |
---|
70 | substring. This has the same effect as putting a C<^> and C<$> |
---|
71 | around each pattern. |
---|
72 | |
---|
73 | =item C<-2> |
---|
74 | |
---|
75 | Lets you give ID3v2 frame ids as search fields. For instance, to |
---|
76 | find everything which has been tagged as having an "Original artist" |
---|
77 | (i.e., It's probably a cover song): |
---|
78 | |
---|
79 | mp3find ~/music -tope . |
---|
80 | |
---|
81 | =item C<-sort> |
---|
82 | |
---|
83 | Which ID3 fields to sort the results by; separate multiple fields |
---|
84 | with commas. The default behavior just returns the filenames in the |
---|
85 | order that L<File::Find> finds them. |
---|
86 | |
---|
87 | =item C<-printf> |
---|
88 | |
---|
89 | The output format for each file found. The available format codes are: |
---|
90 | |
---|
91 | %a - artist |
---|
92 | %t - title |
---|
93 | %b - album |
---|
94 | %n - track number |
---|
95 | %y - year |
---|
96 | %g - genre |
---|
97 | %% - literal '%' |
---|
98 | |
---|
99 | Numeric modifiers may be used; they are interpreted like modifiers to |
---|
100 | the C<%s> code in Perl's C<printf> function. |
---|
101 | |
---|
102 | If no C<-printf> option is used, the full path to the file is printed |
---|
103 | instead. |
---|
104 | |
---|
105 | =item C<< -<field> <pattern> [patterns...] >> |
---|
106 | |
---|
107 | The fields you are searching on. More than one pattern for a given field |
---|
108 | are combined with 'OR', while the fields to be matched are 'AND'-ed together. |
---|
109 | For the list of recognized fields, see L<MP3::Find>. |
---|
110 | |
---|
111 | =back |
---|
112 | |
---|
113 | =head1 AUTHOR |
---|
114 | |
---|
115 | Peter Eichman <peichman@cpan.org> |
---|
116 | |
---|
117 | =head1 COPYRIGHT AND LICENSE |
---|
118 | |
---|
119 | Copyright (c) 2006 by Peter Eichman. All rights reserved. |
---|
120 | |
---|
121 | This program is free software; you can redistribute it and/or |
---|
122 | modify it under the same terms as Perl itself. |
---|
123 | |
---|
124 | =cut |
---|