1998169aa04c29b4734bd66f838e84a4d4cd823a
[id3fs.git] / bin / id3fs
1 #!/usr/bin/perl -w
2 # Ian Beckwith <ianb@erislabs.net>
3 #
4
5 use lib '/home/ianb/projects/id3fs/id3fs/lib';
6 use strict;
7 use Getopt::Long qw(Configure);
8 use ID3FS::DB;
9 use File::Find;
10 use vars qw($me);
11 $me=($0=~/(?:.*\/)?(.*)/)[0];
12
13 my $verbose=0;
14 my $help=0;
15 my $init=0;
16 my @extensions=qw(mp3); # ogg flac);
17 Configure(qw(bundling no_ignore_case));
18 my $optret=GetOptions(
19     "verbose|v"  => \$verbose,
20     "quiet|q"    => sub { $verbose=0; },
21     "help|h"     => \$help,
22     "extensions|e=s" => sub { @extensions=split(/\s+|\s*,\s*/, $_[1]); },
23     "init|i"     => \$init,
24     );
25
26 usage() if(!@ARGV || !$optret || $help);
27
28 my $path=shift;
29 my $db=ID3FS::DB->new($path, $init, $me);
30
31 File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path);
32
33 sub wanted
34 {
35     my $ext='';
36     if(/.*\.(.*)/) { $ext=lc($1); }
37     if(-d)
38     {
39         print("$_\n") if $verbose;
40     }
41     elsif(-f && scalar(grep({ $ext eq lc($_);} @extensions)))
42     {
43         s/^\.\///;
44         $db->add($_);
45     }
46 }
47
48 sub usage
49 {
50     die("Usage: $me [-v] [-q] [-h] [--] file...\n".
51         " -v\tVerbose\n".
52         " -q\tQuiet (default)\n".
53         " -h\tThis help\n".
54         " --\tEnd of options\n");
55 }
56
57 __END__
58
59
60 =head1 NAME
61
62 program - description
63
64 =head1 SYNOPSIS
65
66 B<> [I<-v>] [I<-q>] [I<-h>] [I<file>...]
67
68 =head1 DESCRIPTION
69
70 =head1 OPTIONS
71
72 =over 4
73
74 =item B<-v>
75
76 Enable verbose operation.
77
78 =item B<-q>
79
80 Quiet (no output). This is the default.
81
82 =item B<-h>
83
84 Show a short help message.
85
86 =item B<-->
87
88 End of options.
89
90 =back
91
92 =head1 FILES
93
94 =head1 ENVIRONMENT
95
96 =head1 DIAGNOSTICS
97
98 =head1 BUGS
99
100 None known. Please report any found to ianb@erislabs.net
101
102 =head1 SEE ALSO
103
104 =head1 AUTHOR
105
106 Ian Beckwith <ianb@erislabs.net>
107
108 =head1 AVAILABILITY
109
110 The latest version can be found at:
111
112 B<http://erislabs.net/ianb/projects/id3fs/>
113
114 =head1 COPYRIGHT
115
116 Copyright 2010 Ian Beckwith <ianb@erislabs.net>
117
118 This program is free software: you can redistribute it and/or modify
119 it under the terms of the GNU General Public License as published by
120 the Free Software Foundation; either version 3 of the License, or
121 (at your option) any later version.
122
123 This program is distributed in the hope that it will be useful,
124 but WITHOUT ANY WARRANTY; without even the implied warranty of
125 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
126 GNU General Public License for more details.
127
128 You should have received a copy of the GNU General Public License
129 along with this program.  If not, see <http://www.gnu.org/licenses/>.
130
131 =cut