X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=bin%2Fid3fs-index;h=9493f7ce223ed4054bd47bbf28aaa59cb508d896;hb=40f0c2722d03f8c86d867cddf4f323f992a4065b;hp=1c479f38ea6315e5a4208e504051b67ef5b7a207;hpb=db5c2460d34783d162b2b6677e8768207bc1eaa8;p=id3fs.git diff --git a/bin/id3fs-index b/bin/id3fs-index index 1c479f3..9493f7c 100755 --- a/bin/id3fs-index +++ b/bin/id3fs-index @@ -14,7 +14,9 @@ my $verbose=0; my $help=0; my $basedir=undef; my $dbpath=undef; -my @extensions=qw(mp3); # ogg flac); # FIXME +my $list=0; +my @extensions=qw(mp3 flac ogg); +my $files_pruned; Configure(qw(bundling no_ignore_case)); my $optret=GetOptions( @@ -24,6 +26,7 @@ my $optret=GetOptions( "dir|d=s" => \$basedir, "database|f=s" => \$dbpath, "extensions|e=s" => sub { @extensions=split(/\s+|\s*,\s*/, $_[1]); }, + "list|l" => \$list, ); usage() if(!@ARGV || !$optret || $help); @@ -34,11 +37,24 @@ if(@ARGV > 1 && !defined($basedir)) } my $db=ID3FS::DB->new($me, $dbpath, $basedir, $ARGV[0]); -$db->last_update(time()); - -while(my $path=shift) +if($list) +{ + list_tags($db); +} +else { - File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path); + $db->last_update(time()); + + my $directories_pruned=$db->prune_directories(); + while(my $path=shift) + { + File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path); + } + if($files_pruned || $directories_pruned) + { + print "Removing data from pruned files\n" if $verbose; + $db->remove_unused(); + } } sub wanted @@ -48,6 +64,7 @@ sub wanted if(-d) { print("$_\n") if $verbose; + prune($_); } elsif(-f && scalar(grep({ $ext eq lc($_);} @extensions))) { @@ -56,6 +73,53 @@ sub wanted } } + +sub prune +{ + my $dir=shift; + return unless(opendir(DIR, $dir)); + print "Pruning $dir\n"; + my @oldfiles=$db->files_in($dir); + my @newfiles=grep { !/^\.\.?$/; } readdir(DIR); + closedir(DIR); + @oldfiles=sort @oldfiles; + @newfiles=sort @newfiles; + my %hash; + @hash{@newfiles}=(); + for my $file (@oldfiles) + { + unless(exists($hash{$file})) + { + # FIXME: add path, rebasify + $files_pruned=1; + $db->unindex($file); + } + } +} + + + + +sub list_tags +{ + my($db)=@_; + my @baretags=$db->bare_tags(); + my $valtags=$db->tags_with_values(); + if(@baretags) + { + print "BARE TAGS\n"; + print join(', ', sort @baretags), "\n\n"; + } + if(keys(%$valtags)) + { + print "TAGS WITH VALUES\n"; + for my $key (sort keys %$valtags) + { + print "$key: ", join(', ', sort(@{$valtags->{$key}})), "\n"; + } + } +} + sub usage { die("Usage: $me [-vqh] [-d basedir] [-f dbpath] [-e mp3,ogg,flac] [--] DIR...\n".