+# id3fs - a FUSE-based filesystem for browsing audio metadata
+# Copyright (C) 2010 Ian Beckwith <ianb@erislabs.net>
+#
+# 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 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
package ID3FS::DB;
use strict;
$self->{me}=shift;
$self->{verbose}=shift;
my $init=shift;
- my $dbpath=shift;
$self->{base}=shift;
- my $fallbackdir=shift;
-
- $self->{dbpath}=$self->find_db($init, $dbpath, $fallbackdir);
- return undef unless($self->{dbpath});
+ $self->{dbpath}=shift || ($self->{base} . "/" . $dbfile);
$self->{absbase}=Cwd::abs_path($self->{base});
my $connectstr="dbi:SQLite:dbname=$self->{dbpath}";
sub find_db
{
- my($self, $init, $dbpath, $fallbackdir)=@_;
- my $file=undef;
+ # class method
+ shift if(ref($_[0]) eq "ID3FS::DB");
+
+ my($me, $init, @dirs)=@_;
my $base=undef;
- if(defined($dbpath))
- {
- $file=$dbpath;
- }
- if(defined ($self->{base}))
- {
- $file="$self->{base}/$dbfile" unless defined($file);
- $base=$self->{base};
- }
- elsif(defined($fallbackdir) && -d $fallbackdir)
+ for my $dir (@dirs)
{
- my $path=Cwd::abs_path($fallbackdir);
+ my $path=Cwd::abs_path($dir);
do
{
- $file="$path/$dbfile";
$base=$path;
$path=~s/(.*)\/.*/$1/;
}
- while(! -f $file && length($path) && -d $path);
- if(! -f $file)
+ while(! -f "$base/$dbfile" && length($path) && -d $path);
+ if(-f "$base/$dbfile")
{
- $file="$fallbackdir/$dbfile";
- $base=$fallbackdir;
+ return $base;
}
}
- else
- {
- print "$self->{me}: $fallbackdir: not a directory\n";
- return undef;
- }
- if(!-f $file && !$init)
+ if(!-f "$base/$dbfile")
{
- print "$self->{me}: db not found at $file\n";
- return undef;
+ unless($init)
+ {
+ print "$me: db not found at $base/$dbfile\n";
+ return undef;
+ }
+ $base=$dirs[0];
+
}
- $self->{base}=$base;
- return $file;
+ return $base;
}
sub base_dir { return shift->{base}; }
{
$self->add_tag($file_id, "haspic", undef);
}
+
+ if($self->ok($audiotype))
+ {
+ $self->add_tag($file_id, "audiotype", $audiotype);
+ }
}
sub add_tag