use strict;
use Getopt::Long qw(Configure);
use ID3FS::DB;
+use File::Find;
use vars qw($me);
$me=($0=~/(?:.*\/)?(.*)/)[0];
my $verbose=0;
my $help=0;
-my $init=0;
+my $basedir=undef;
+my $dbpath=undef;
+
+my @extensions=qw(mp3); # ogg flac); # FIXME
Configure(qw(bundling no_ignore_case));
my $optret=GetOptions(
- "verbose|v" => \$verbose,
- "quiet|q" => sub { $verbose=0; },
- "help|h" => \$help,
- "init|i" => \$init,
+ "verbose|v" => \$verbose,
+ "quiet|q" => sub { $verbose=0; },
+ "help|h" => \$help,
+ "basedir|d=s" => \$basedir,
+ "database|db=s" => \$dbpath,
+ "extensions|e=s" => sub { @extensions=split(/\s+|\s*,\s*/, $_[1]); },
);
usage() if(!@ARGV || !$optret || $help);
-my $path=shift;
-my $db=ID3FS::DB->new($path, $init, $me);
+if(@ARGV > 1 && !defined($basedir))
+{
+ die("$me: --basedir must be specified if multiple paths are supplied\n");
+}
+
+my $db=ID3FS::DB->new($me, $dbpath, $basedir, $ARGV[0]);
+
+while(my $path=shift)
+{
+ File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path);
+}
+
+sub wanted
+{
+ my $ext='';
+ if(/.*\.(.*)/) { $ext=lc($1); }
+ if(-d)
+ {
+ print("$_\n") if $verbose;
+ }
+ elsif(-f && scalar(grep({ $ext eq lc($_);} @extensions)))
+ {
+ s/^\.\///;
+ $db->add($_);
+ }
+}
sub usage
{