source: mp3-find/trunk/bin/mp3find @ 25

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