ID3FS: use File::Find to recursively add files
authorIan Beckwith <ianb@erislabs.net>
Sun, 19 Sep 2010 21:40:12 +0000 (22:40 +0100)
committerIan Beckwith <ianb@erislabs.net>
Sun, 19 Sep 2010 21:40:12 +0000 (22:40 +0100)
bin/id3fs
lib/ID3FS/DB.pm

index eb0b2bd..485eabd 100755 (executable)
--- a/bin/id3fs
+++ b/bin/id3fs
@@ -6,17 +6,20 @@ 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,
     );
 
@@ -25,6 +28,22 @@ 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".
index 6b0f844..32db70a 100644 (file)
@@ -80,6 +80,11 @@ sub cmd_sth
     return $sth;
 }
 
+sub add
+{
+    my($self,$path)=@_;
+}
+
 sub cmd
 {
     my ($self, @args)=@_;