X-Git-Url: http://erislabs.net/gitweb/?p=id3fs.git;a=blobdiff_plain;f=lib%2FID3FS%2FDB.pm;h=ea632a5f19371a7ada40c539a960314085cfb9dd;hp=273f6dcad5ac82d05887f8767f2f4a730bbfaecb;hb=06c9a0b121355c67fc7fde20c3a3e194b176bd00;hpb=a474cec8c4e0ea282f21902dc2bffdabb82667c3 diff --git a/lib/ID3FS/DB.pm b/lib/ID3FS/DB.pm index 273f6dc..ea632a5 100644 --- a/lib/ID3FS/DB.pm +++ b/lib/ID3FS/DB.pm @@ -37,6 +37,7 @@ sub new my $init=shift; $self->{base}=shift; $self->{dbpath}=shift || ($self->{base} . "/" . $dbfile); + $self->{dbpath}=Cwd::abs_path($self->{dbpath}); $self->{absbase}=Cwd::abs_path($self->{base}); my $connectstr="dbi:SQLite:dbname=$self->{dbpath}"; @@ -184,22 +185,16 @@ sub tag_has_values sub relativise { - my($self, $path, $name, $mountpoint)=@_; - my $id3fs_path=$self->{dbpath}; - $id3fs_path=~s/(.*)\/.*/$1/; + my($self, $path, $name, $mountpoint, $querypath)=@_; my $rpath="$self->{absbase}/$path"; - my $vpath="$mountpoint/$id3fs_path"; + my $vpath=$mountpoint . $querypath; my @path=split(/\//,$rpath); my @rel=split(/\//,$vpath); - #absolute paths have empty first element due to leading / + # drop filename from rel + pop @rel; + # absolute paths have empty first element due to leading / shift(@path) if($path[0] eq ""); shift(@rel) if($rel[0] eq ""); - if($path[0] ne $rel[0]) - { - #no path in common, return absolute - print "FAIL: NO PATHS IN COMMON\n"; - return $name; - } # f: /home/foo/bar/baz.mp3 # r: /home/ianb/music/albums while(@path && @rel && ($path[0] eq $rel[0])) @@ -238,13 +233,17 @@ sub add my $audiotype=$file->audiotype(); my @tags=$file->tags(); my $haspic=$file->haspic(); + my $channels=$file->channels(); + my $bitrate=$file->bitrate(); + my $samplerate=$file->samplerate(); $artist=undef unless($self->ok($artist)); print "$self->{me}: $path: no artist tag defined\n" unless(defined($artist)); my $artist_id=$self->add_to_table("artists", $artist); my $path_id=$self->add_to_table("paths", $pathpart); $album=undef unless($self->ok($album)); - if($self->{verbose} && !defined($album)) +# if($self->{verbose} && !defined($album)) FIXME + if(!defined($album)) { print "$self->{me}: $path: no album tag defined\n"; } @@ -254,12 +253,19 @@ sub add { "artists_id" => $artist_id, "albums_id" => $albums_id, "paths_id" => $path_id }); - for my $tag (@tags) + if(@tags) { - $self->add_tag($file_id, @$tag); + for my $tag (@tags) + { + $self->add_tag($file_id, @$tag); + } + } + else + { + $self->add_tag($file_id, "UNTAGGED"); } - $year="UNKNOWN" unless($self->ok($year)); + $year="UNKNOWN" if(!$self->ok($year) || $year =~ /^0+$/); $self->add_tag($file_id, "year", $year); if($year=~/^(\d\d\d)\d$/) { @@ -284,6 +290,27 @@ sub add { $self->add_tag($file_id, "audiotype", $audiotype); } + + if($self->ok($channels)) + { + if ($channels eq "2") { $channels="stereo"; } + elsif ($channels eq "1") { $channels="mono"; } + elsif ($channels eq "0") { $channels="UNKNOWN"; } + $self->add_tag($file_id, "channels", $channels); + } + + if($self->ok($bitrate)) + { + $bitrate="UNKNOWN" if($bitrate=~/^0+$/); + $self->add_tag($file_id, "bitrate", $bitrate); + } + + if($self->ok($samplerate)) + { + $samplerate="UNKNOWN" if($samplerate=~/^0+$/); + $self->add_tag($file_id, "samplerate", $samplerate); + } + } sub add_tag @@ -533,19 +560,19 @@ CREATE TABLE id3fs ( CREATE TABLE paths ( id INTEGER, name text, - PRIMARY KEY(id DESC) + PRIMARY KEY(id ASC) ); CREATE TABLE artists ( id INTEGER, name text, - PRIMARY KEY(id DESC) + PRIMARY KEY(id ASC) ); CREATE TABLE albums ( id INTEGER, name text, - PRIMARY KEY(id DESC) + PRIMARY KEY(id ASC) ); CREATE TABLE files ( @@ -554,7 +581,7 @@ CREATE TABLE files ( artists_id, albums_id, paths_id, - PRIMARY KEY(id DESC), + PRIMARY KEY(id ASC), FOREIGN KEY(artists_id) REFERENCES artists(id) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY(albums_id) REFERENCES albums(id) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY(paths_id) REFERENCES paths(id) ON DELETE CASCADE ON UPDATE CASCADE @@ -564,7 +591,7 @@ CREATE TABLE tags ( id INTEGER, parents_id INTEGER, name text, - PRIMARY KEY(id DESC) + PRIMARY KEY(id ASC) ); CREATE TABLE files_x_tags (