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