[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 | use lib '/home/peter/projects/mp3-find/lib'; |
---|
| 6 | |
---|
| 7 | use MP3::Find qw(Filesystem); |
---|
| 8 | use MP3::Find::Util qw(build_query); |
---|
| 9 | use File::Spec::Functions qw(catfile); |
---|
| 10 | |
---|
| 11 | GetOptions( |
---|
| 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 | |
---|
| 18 | my ($DIRS, $QUERY) = build_query(@ARGV); |
---|
| 19 | push @$DIRS, '.' unless @$DIRS; |
---|
| 20 | |
---|
| 21 | print "$_\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 | |
---|
| 33 | mp3find - 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 | |
---|
| 56 | The real guts of the operation are in L<MP3::Find>. |
---|
| 57 | |
---|
| 58 | =head2 OPTIONS |
---|
| 59 | |
---|
| 60 | =over |
---|
| 61 | |
---|
[3] | 62 | =item C<-ignore-case>, C<-i> |
---|
[1] | 63 | |
---|
| 64 | Case insensitive matching. |
---|
| 65 | |
---|
[3] | 66 | =item C<-exact-match>, C<-w> |
---|
[1] | 67 | |
---|
[3] | 68 | All search patterns must match the entire value, and not just a |
---|
| 69 | substring. This has the same effect as putting a C<^> and C<$> |
---|
| 70 | around each pattern. |
---|
[1] | 71 | |
---|
| 72 | =item C<-sort> |
---|
| 73 | |
---|
| 74 | Which ID3 fields to sort the results by; separate multiple fields |
---|
| 75 | with commas. The default behavior just returns the filenames in the |
---|
| 76 | order that L<File::Find> finds them. |
---|
| 77 | |
---|
| 78 | =item C<-printf> |
---|
| 79 | |
---|
| 80 | The 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 | |
---|
| 90 | Numeric modifiers may be used; they are interpreted like modifiers to |
---|
| 91 | the C<%s> code in Perl's C<printf> function. |
---|
| 92 | |
---|
| 93 | If no C<-printf> option is used, the full path to the file is printed |
---|
| 94 | instead. |
---|
| 95 | |
---|
[3] | 96 | =item C<< -<field> <pattern> [patterns...] >> |
---|
[1] | 97 | |
---|
[3] | 98 | The fields you are searching on. More than one pattern for a given field |
---|
| 99 | are combined with 'OR', while the fields to be matched are 'AND'-ed together. |
---|
| 100 | For the list of recognized fields, see L<MP3::Find>. |
---|
[1] | 101 | |
---|
| 102 | =back |
---|
| 103 | |
---|
| 104 | =head1 AUTHOR |
---|
| 105 | |
---|
| 106 | Peter Eichman <peichman@cpan.org> |
---|
| 107 | |
---|
[3] | 108 | =head1 COPYRIGHT AND LICENSE |
---|
| 109 | |
---|
| 110 | Copyright (c) 2006 by Peter Eichman. All rights reserved. |
---|
| 111 | |
---|
| 112 | This program is free software; you can redistribute it and/or |
---|
| 113 | modify it under the same terms as Perl itself. |
---|
| 114 | |
---|
[1] | 115 | =cut |
---|