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

Last change on this file since 23 was 23, checked in by peter, 18 years ago
  • removed hardcoded "use lib '/home/peter/projects/mp3-find/lib'" form distrubuted scripts
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    '2'             => \my $USE_ID3V2,
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    use_id3v2   => $USE_ID3V2,
30);
31
32=head1 NAME
33
34mp3find - 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
57The 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
65Case insensitive matching.
66
67=item C<-exact-match>, C<-w>
68
69All search patterns must match the entire value, and not just a
70substring. This has the same effect as putting a C<^> and C<$>
71around each pattern.
72
73=item C<-2>
74
75Lets you give ID3v2 frame ids as search fields. For instance, to
76find 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
83Which ID3 fields to sort the results by; separate multiple fields
84with commas. The default behavior just returns the filenames in the
85order that L<File::Find> finds them.
86
87=item C<-printf>
88
89The 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
99Numeric modifiers may be used; they are interpreted like modifiers to
100the C<%s> code in Perl's C<printf> function.
101
102If no C<-printf> option is used, the full path to the file is printed
103instead.
104
105=item C<< -<field> <pattern> [patterns...] >>
106
107The fields you are searching on. More than one pattern for a given field
108are combined with 'OR', while the fields to be matched are 'AND'-ed together.
109For the list of recognized fields, see L<MP3::Find>.
110
111=back
112
113=head1 AUTHOR
114
115Peter Eichman <peichman@cpan.org>
116
117=head1 COPYRIGHT AND LICENSE
118
119Copyright (c) 2006 by Peter Eichman. All rights reserved.
120
121This program is free software; you can redistribute it and/or
122modify it under the same terms as Perl itself.
123
124=cut
Note: See TracBrowser for help on using the repository browser.