[1] | 1 | #!/usr/bin/perl -w |
---|
| 2 | use strict; |
---|
| 3 | |
---|
| 4 | use Getopt::Long qw(:config pass_through); # use pass_through so we can get the query args |
---|
| 5 | |
---|
| 6 | use MP3::Find qw(Filesystem); |
---|
| 7 | use MP3::Find::Util qw(build_query); |
---|
| 8 | use File::Spec::Functions qw(catfile); |
---|
| 9 | |
---|
| 10 | GetOptions( |
---|
| 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 | |
---|
| 17 | my ($DIRS, $QUERY) = build_query(@ARGV); |
---|
| 18 | push @$DIRS, '.' unless @$DIRS; |
---|
| 19 | |
---|
| 20 | print "$_\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 | ); |
---|
| 29 | |
---|
| 30 | =head1 NAME |
---|
| 31 | |
---|
| 32 | mp3find - Find MP3 files based on their ID3 tags or info |
---|
| 33 | |
---|
| 34 | =head1 SYNOPSIS |
---|
| 35 | |
---|
| 36 | $ mp3find ~/cds -i -artist beatles -sort year,album,tracknum -printf '%2n. %a - %t (%b: %y)' |
---|
| 37 | 1. The Beatles - Magical Mystery Tour (Magical Mystery Tour: 1967) |
---|
| 38 | 2. The Beatles - The Fool on the Hill (Magical Mystery Tour: 1967) |
---|
| 39 | 3. The Beatles - Flying (Magical Mystery Tour: 1967) |
---|
| 40 | 4. The Beatles - Blue Jay Way (Magical Mystery Tour: 1967) |
---|
| 41 | 5. The Beatles - Your Mother Should Know (Magical Mystery Tour: 1967) |
---|
| 42 | 6. The Beatles - I Am The Walrus (Magical Mystery Tour: 1967) |
---|
| 43 | # etc. |
---|
| 44 | |
---|
| 45 | # shuffle and play your entire mp3 collection |
---|
| 46 | $ mp3find | xargs madplay -z |
---|
| 47 | |
---|
| 48 | # ...or just your Sabbath |
---|
| 49 | $ mp3find -i -artist 'black sabbath' | xargs madplay -z |
---|
| 50 | |
---|
| 51 | =head1 DESCRIPTION |
---|
| 52 | |
---|
| 53 | $ mp3find [options] [directory] [<-field> <pattern> [<-field> <pattern> ...]] |
---|
| 54 | |
---|
| 55 | The real guts of the operation are in L<MP3::Find>. |
---|
| 56 | |
---|
| 57 | =head2 OPTIONS |
---|
| 58 | |
---|
| 59 | =over |
---|
| 60 | |
---|
[3] | 61 | =item C<-ignore-case>, C<-i> |
---|
[1] | 62 | |
---|
| 63 | Case insensitive matching. |
---|
| 64 | |
---|
[3] | 65 | =item C<-exact-match>, C<-w> |
---|
[1] | 66 | |
---|
[3] | 67 | All search patterns must match the entire value, and not just a |
---|
| 68 | substring. This has the same effect as putting a C<^> and C<$> |
---|
| 69 | around each pattern. |
---|
[1] | 70 | |
---|
| 71 | =item C<-sort> |
---|
| 72 | |
---|
| 73 | Which ID3 fields to sort the results by; separate multiple fields |
---|
| 74 | with commas. The default behavior just returns the filenames in the |
---|
| 75 | order that L<File::Find> finds them. |
---|
| 76 | |
---|
| 77 | =item C<-printf> |
---|
| 78 | |
---|
| 79 | The output format for each file found. The available format codes are: |
---|
| 80 | |
---|
| 81 | %a - artist |
---|
| 82 | %t - title |
---|
| 83 | %b - album |
---|
| 84 | %n - track number |
---|
| 85 | %y - year |
---|
| 86 | %g - genre |
---|
| 87 | %% - literal '%' |
---|
| 88 | |
---|
| 89 | Numeric modifiers may be used; they are interpreted like modifiers to |
---|
| 90 | the C<%s> code in Perl's C<printf> function. |
---|
| 91 | |
---|
| 92 | If no C<-printf> option is used, the full path to the file is printed |
---|
| 93 | instead. |
---|
| 94 | |
---|
[3] | 95 | =item C<< -<field> <pattern> [patterns...] >> |
---|
[1] | 96 | |
---|
[3] | 97 | The fields you are searching on. More than one pattern for a given field |
---|
| 98 | are combined with 'OR', while the fields to be matched are 'AND'-ed together. |
---|
| 99 | For the list of recognized fields, see L<MP3::Find>. |
---|
[1] | 100 | |
---|
| 101 | =back |
---|
| 102 | |
---|
| 103 | =head1 AUTHOR |
---|
| 104 | |
---|
| 105 | Peter Eichman <peichman@cpan.org> |
---|
| 106 | |
---|
[3] | 107 | =head1 COPYRIGHT AND LICENSE |
---|
| 108 | |
---|
| 109 | Copyright (c) 2006 by Peter Eichman. All rights reserved. |
---|
| 110 | |
---|
| 111 | This program is free software; you can redistribute it and/or |
---|
| 112 | modify it under the same terms as Perl itself. |
---|
| 113 | |
---|
[1] | 114 | =cut |
---|