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

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