source: mp3-find/trunk/bin/mp3find

Last change on this file was 40, checked in by peter, 13 years ago

Reversed accidental commit of extra changes in r39

File size: 3.1 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<-sort>
73
74Which ID3 fields to sort the results by; separate multiple fields
75with commas. The default behavior just returns the filenames in the
76order that L<File::Find> finds them.
77
78=item C<-printf>
79
80The output format for each file found. The available format codes are:
81
82    %a - artist
83    %t - title
84    %b - album
85    %n - track number
86    %y - year
87    %g - genre
88    %% - literal '%'
89
90Numeric modifiers may be used; they are interpreted like modifiers to
91the C<%s> code in Perl's C<printf> function.
92
93If no C<-printf> option is used, the full path to the file is printed
94instead.
95
96=item C<< -<field> <pattern> [patterns...] >>
97
98The fields you are searching on. More than one pattern for a given field
99are combined with 'OR', while the fields to be matched are 'AND'-ed together.
100For the list of recognized fields, see L<MP3::Find>.
101
102=back
103
104=head1 AUTHOR
105
106Peter Eichman <peichman@cpan.org>
107
108=head1 COPYRIGHT AND LICENSE
109
110Copyright (c) 2006 by Peter Eichman. All rights reserved.
111
112This program is free software; you can redistribute it and/or
113modify it under the same terms as Perl itself.
114
115=cut
Note: See TracBrowser for help on using the repository browser.