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

Last change on this file since 1 was 1, checked in by peter, 19 years ago

Initial import

File size: 2.6 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
5use lib '/home/peter/projects/mp3-find/lib';
6
7use MP3::Find qw(Filesystem);
8use MP3::Find::Util qw(build_query);
9use File::Spec::Functions qw(catfile);
10
11GetOptions(
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);
17
18my ($DIRS, $QUERY) = build_query(@ARGV);
19push @$DIRS, '.' unless @$DIRS;
20
21print "$_\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);
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<-i>
63
64Case insensitive matching.
65
66=item C<-w>
67
68Match only whole words.
69
70=item C<-sort>
71
72Which ID3 fields to sort the results by; separate multiple fields
73with commas. The default behavior just returns the filenames in the
74order that L<File::Find> finds them.
75
76=item C<-printf>
77
78The output format for each file found. The available format codes are:
79
80    %a - artist
81    %t - title
82    %b - album
83    %n - track number
84    %y - year
85    %g - genre
86    %% - literal '%'
87
88Numeric modifiers may be used; they are interpreted like modifiers to
89the C<%s> code in Perl's C<printf> function.
90
91If no C<-printf> option is used, the full path to the file is printed
92instead.
93
94=item C<< <-field> <pattern> >>
95
96The fields you are searching on. These are and-ed together. For the list
97of recognized fields, see L<MP3::Find>.
98
99=back
100
101=head1 AUTHOR
102
103Peter Eichman <peichman@cpan.org>
104
105=cut
Note: See TracBrowser for help on using the repository browser.