From: Ian Beckwith Date: Sun, 3 Oct 2010 00:51:54 +0000 (+0100) Subject: tags hierarchy schema change: change add X-Git-Tag: debian/1.0-1~137 X-Git-Url: http://erislabs.net/gitweb/?p=id3fs.git;a=commitdiff_plain;h=b21a945bddb2174e437d0549956c0bfa9f7bbe73 tags hierarchy schema change: change add --- diff --git a/lib/ID3FS/AudioFile.pm b/lib/ID3FS/AudioFile.pm index 4086f63..59e0dfa 100644 --- a/lib/ID3FS/AudioFile.pm +++ b/lib/ID3FS/AudioFile.pm @@ -83,34 +83,21 @@ sub year sub tags { my $self=shift; - my @tags=$self->{audiofile}->tags(); - return({}) unless(@tags); - my $tags={}; - if(@tags) + my @intags=$self->{audiofile}->tags(); + my @outtags=(); + return() unless(@intags); + @intags = grep { defined($_); } @intags; + # combine then split on commas + # so multiple comma-delimited tags will work + @intags=split(/\s*,\s*/, join(', ', @intags)); + for my $tag (@intags) { - @tags = grep { defined($_); } @tags; - # combine then split on commas - # so multiple comma-delimited tags will work - @tags=split(/\s*,\s*/, join(', ', @tags)); - for my $tag (@tags) - { - next unless(length($tag)); - next unless($tag =~ /\S+/); - $tag=$self->sanitise($tag); - - if($tag=~/([^\/]+)\/(.*)/) - { - my $tagname = $1; - my $tagval = $self->stripslashes($2); - $tags->{$tagname}=$tagval; - } - else - { - $tags->{$tag}=undef; - } - } + next unless(length($tag)); + next unless($tag =~ /\S+/); + $tag=$self->sanitise($tag); + push(@outtags, [ split(/\s*\/\s*/, $tag) ]); } - return $tags; + return @outtags; } sub sanitise diff --git a/lib/ID3FS/DB.pm b/lib/ID3FS/DB.pm index 07a5f86..17e215c 100644 --- a/lib/ID3FS/DB.pm +++ b/lib/ID3FS/DB.pm @@ -524,7 +524,7 @@ sub add my $v1genre=$file->v1genre(); my $year=$file->year(); my $audiotype=$file->audiotype(); - my $tags=$file->tags(); + my @tags=$file->tags(); my $haspic=$file->haspic(); $artist=undef unless($self->ok($artist)); @@ -542,9 +542,9 @@ sub add { "artists_id" => $artist_id, "albums_id" => $albums_id, "paths_id" => $path_id }); - for my $tag (keys %$tags) + for my $tag (@tags) { - $self->add_tag($file_id, $tag, $tags->{$tag}); + $self->add_tag($file_id, @$tag); } if($self->ok($year)) @@ -569,17 +569,16 @@ sub add sub add_tag { - my($self, $file_id, $tag, $val)=@_; - my $tag_id=$self->add_to_table("tags", $tag); - $self->add_relation("files_x_tags", - { "files_id" => $file_id, - "tags_id" => $tag_id }); - if(defined($val)) + my($self, $file_id, @tags)=@_; + my $parent_id=undef; + for my $tag (@tags) { - my $val_id=$self->add_to_table("tagvals", $val); - $self->add_relation("tags_x_tagvals", - { "tags_id" => $tag_id, - "tagvals_id" => $val_id }); + my $tag_id=$self->add_to_table("tags", $tag, + { "parents_id" => $parent_id }); + $self->add_relation("files_x_tags", + { "files_id" => $file_id, + "tags_id" => $tag_id }); + $parent_id=$tag_id; } } @@ -819,6 +818,7 @@ CREATE TABLE files ( CREATE TABLE tags ( id INTEGER PRIMARY KEY, + parents_id INTEGER, name text );