ID3FS: use File::Find to recursively add files
[id3fs.git] / bin / id3fs
index 31a480f..485eabd 100755 (executable)
--- a/bin/id3fs
+++ b/bin/id3fs
@@ -2,23 +2,48 @@
 # 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 $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
+{
+    my $ext='';
+    if(/.*\.(.*)/) { $ext=lc($1); }
+    if(-d)
+    {
+       print("$_\n") if $verbose;
+    }
+    elsif(-f && scalar(grep({ $ext eq lc($_);} @extensions)))
+    {
+       $db->add($_);
+    }
+}
+
 sub usage
 {
     die("Usage: $me [-v] [-q] [-h] [--] file...\n".