# Ian Beckwith <ianb@erislabs.net>
#
+use lib '/home/ianb/projects/id3fs/id3fs/lib';
use strict;
+use Getopt::Long qw(Configure);
+use ID3FS::DB;
+use File::Find;
use vars qw($me);
$me=($0=~/(?:.*\/)?(.*)/)[0];
my $verbose=0;
-my $doneargs=0;
-my $donesomething=0;
-
-while($_=shift)
+my $help=0;
+my $init=0;
+my @extensions=qw(mp3 ogg flac);
+Configure(qw(bundling no_ignore_case));
+my $optret=GetOptions(
+ "verbose|v" => \$verbose,
+ "quiet|q" => sub { $verbose=0; },
+ "help|h" => \$help,
+ "extensions|e=s" => sub { @extensions=split(/\s+|\s*,\s*/, $_[1]); },
+ "init|i" => \$init,
+ );
+
+usage() if(!@ARGV || !$optret || $help);
+
+my $path=shift;
+my $db=ID3FS::DB->new($path, $init, $me);
+
+File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path);
+
+sub wanted
{
- if(/^-/ && !$doneargs)
+ my $ext='';
+ if(/.*\.(.*)/) { $ext=lc($1); }
+ if(-d)
{
- if (/-v/) { $verbose=1; }
- elsif(/-q/) { $verbose=0; }
- elsif(/--/) { $doneargs=1; }
- elsif(/-h/) { usage(); }
- else { usage(); }
- next;
+ print("$_\n") if $verbose;
+ }
+ elsif(-f && scalar(grep({ $ext eq lc($_);} @extensions)))
+ {
+ s/^\.\///;
+ $db->add($_);
}
- $donesomething=1;
- my $file=$_;
-}
-
-unless($donesomething)
-{
- usage();
}
-
sub usage
{
die("Usage: $me [-v] [-q] [-h] [--] file...\n".
The latest version can be found at:
-B<http://erislabs.net/ianb/projects//>
+B<http://erislabs.net/ianb/projects/id3fs/>
=head1 COPYRIGHT
-Copyright 2008 Ian Beckwith <ianb@erislabs.net>
+Copyright 2010 Ian Beckwith <ianb@erislabs.net>
-This program is free software; you can redistribute it and/or modify
+This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or (at
-your option) any later version.
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+along with this program. If not, see <http://www.gnu.org/licenses/>.
=cut