X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2FID3FS%2FDB.pm;h=14f55c5b723e14f830999110575adaa4b13a4c68;hb=3cfb86272c06fe583e4eea36c27a5383115ff4c3;hp=246cd92dc17d351edb171773f667dbef76797fa8;hpb=6c6aa71f693295bf263f86d20dd43b5d001fbfa9;p=id3fs.git diff --git a/lib/ID3FS/DB.pm b/lib/ID3FS/DB.pm index 246cd92..14f55c5 100644 --- a/lib/ID3FS/DB.pm +++ b/lib/ID3FS/DB.pm @@ -19,12 +19,8 @@ sub new $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}"; @@ -50,46 +46,36 @@ sub new 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})) + for my $dir (@dirs) { - $file="$self->{base}/$dbfile" unless defined($file); - $base=$self->{base}; - } - elsif(defined($fallbackdir) && -d $fallbackdir) - { - 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 + if(!-f "$base/$dbfile") { - print "$self->{me}: $fallbackdir: not a directory\n"; - return undef; - } - if(!-f $file && !$init) - { - 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}; } @@ -279,6 +265,11 @@ sub add { $self->add_tag($file_id, "haspic", undef); } + + if($self->ok($audiotype)) + { + $self->add_tag($file_id, "audiotype", $audiotype); + } } sub add_tag