projects
/
id3fs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
merge PathElement::* into Path::Node
[id3fs.git]
/
lib
/
ID3FS
/
Path.pm
diff --git
a/lib/ID3FS/Path.pm
b/lib/ID3FS/Path.pm
index
96fd323
..
4947256
100644
(file)
--- a/
lib/ID3FS/Path.pm
+++ b/
lib/ID3FS/Path.pm
@@
-2,12
+2,6
@@
package ID3FS::Path;
use strict;
use warnings;
use strict;
use warnings;
-use ID3FS::PathElement::Artist;
-use ID3FS::PathElement::Album;
-use ID3FS::PathElement::Boolean;
-use ID3FS::PathElement::File;
-use ID3FS::PathElement::Tag;
-use ID3FS::PathElement::Tagval;
use ID3FS::Path::Node;
our ($STATE_INVALID, $STATE_ROOT, $STATE_TAG, $STATE_TAGVAL,
use ID3FS::Path::Node;
our ($STATE_INVALID, $STATE_ROOT, $STATE_TAG, $STATE_TAGVAL,
@@
-88,7
+82,7
@@
sub dirents
elsif($state==$STATE_TAG || $state==$STATE_TAGVAL)
{
if($state==$STATE_TAG && $self->at("tag") &&
elsif($state==$STATE_TAG || $state==$STATE_TAGVAL)
{
if($state==$STATE_TAG && $self->at("tag") &&
- $self->{db}->tag_has_values($self->tail()->
{id}
))
+ $self->{db}->tag_has_values($self->tail()->
id()
))
{
@dents=$self->tags();
}
{
@dents=$self->tags();
}
@@
-166,12
+160,12
@@
sub parse
elsif($name eq "NOT")
{
$root_not=1;
elsif($name eq "NOT")
{
$root_not=1;
- push(@{$self->{elements}}, ID3FS::Path
Element::Boolean->new($self->{db}
, $name));
+ push(@{$self->{elements}}, ID3FS::Path
::Node->new($self->{db}, "boolean"
, $name));
$self->state($STATE_BOOLEAN);
}
else
{
$self->state($STATE_BOOLEAN);
}
else
{
- $tag=ID3FS::Path
Element::Tag->new($self->{db}
, $name);
+ $tag=ID3FS::Path
::Node->new($self->{db},"tag"
, $name);
if($tag)
{
push(@{$self->{elements}}, $tag);
if($tag)
{
push(@{$self->{elements}}, $tag);
@@
-189,10
+183,10
@@
sub parse
my $tag=$self->tail();
# print "SM: TAG/TAGVAL($state): $name\n";
if($state==$STATE_TAG && $self->is("tag", $tag) &&
my $tag=$self->tail();
# print "SM: TAG/TAGVAL($state): $name\n";
if($state==$STATE_TAG && $self->is("tag", $tag) &&
- $self->{db}->tag_has_values($tag->
{id}
))
+ $self->{db}->tag_has_values($tag->
id()
))
{
{
-# print "Parsing: parent: $tag->
{id}
\n";
- my $tagval=ID3FS::Path
Element::Tag->new($self->{db}, $name, $tag->{id}
);
+# print "Parsing: parent: $tag->
id()
\n";
+ my $tagval=ID3FS::Path
::Node->new($self->{db}, "tag", $name, $tag->id()
);
if(defined($tagval))
{
$self->state($STATE_TAGVAL);
if(defined($tagval))
{
$self->state($STATE_TAGVAL);
@@
-215,16
+209,16
@@
sub parse
elsif($name eq "AND")
{
$self->state($STATE_BOOLEAN);
elsif($name eq "AND")
{
$self->state($STATE_BOOLEAN);
- push(@{$self->{elements}}, ID3FS::Path
Element::Boolean->new($self->{db}
, $name));
+ push(@{$self->{elements}}, ID3FS::Path
::Node->new($self->{db}, "boolean"
, $name));
}
elsif($name eq "OR")
{
$self->state($STATE_BOOLEAN);
}
elsif($name eq "OR")
{
$self->state($STATE_BOOLEAN);
- push(@{$self->{elements}}, ID3FS::Path
Element::Boolean->new($self->{db}
, $name));
+ push(@{$self->{elements}}, ID3FS::Path
::Node->new($self->{db}, "boolean"
, $name));
}
else
{
}
else
{
- my $artist=ID3FS::Path
Element::Artist->new($self->{db}
, $name);
+ my $artist=ID3FS::Path
::Node->new($self->{db}, "artist"
, $name);
if($artist)
{
push(@{$self->{elements}}, $artist);
if($artist)
{
push(@{$self->{elements}}, $artist);
@@
-249,11
+243,11
@@
sub parse
if($allownot && $name eq "NOT")
{
$self->state($STATE_BOOLEAN);
if($allownot && $name eq "NOT")
{
$self->state($STATE_BOOLEAN);
- push(@{$self->{elements}}, ID3FS::Path
Element::Boolean->new($self->{db}
, $name));
+ push(@{$self->{elements}}, ID3FS::Path
::Node->new($self->{db}, "boolean"
, $name));
}
else
{
}
else
{
- my $tag=ID3FS::Path
Element::Tag->new($self->{db}
, $name);
+ my $tag=ID3FS::Path
::Node->new($self->{db}, "tag"
, $name);
if($tag)
{
push(@{$self->{elements}}, $tag);
if($tag)
{
push(@{$self->{elements}}, $tag);
@@
-279,7
+273,7
@@
sub parse
}
else
{
}
else
{
- my $album=ID3FS::Path
Element::Album->new($self->{db}
, $name);
+ my $album=ID3FS::Path
::Node->new($self->{db}, "album"
, $name);
if($album)
{
push(@{$self->{elements}}, $album);
if($album)
{
push(@{$self->{elements}}, $album);
@@
-294,7
+288,7
@@
sub parse
elsif($state==$STATE_TRACKLIST)
{
# print "SM: TRACKLIST: $name\n";
elsif($state==$STATE_TRACKLIST)
{
# print "SM: TRACKLIST: $name\n";
- my $track=ID3FS::Path
Element::File->new($self->{db}
, $name);
+ my $track=ID3FS::Path
::Node->new($self->{db}, "file"
, $name);
if($track)
{
push(@{$self->{elements}}, $track);
if($track)
{
push(@{$self->{elements}}, $track);
@@
-323,7
+317,7
@@
sub parse
}
else
{
}
else
{
- my $artist=ID3FS::Path
Element::Artist->new($self->{db}
, $name);
+ my $artist=ID3FS::Path
::Node->new($self->{db}, "artist"
, $name);
if($artist)
{
push(@{$self->{elements}}, $artist);
if($artist)
{
push(@{$self->{elements}}, $artist);
@@
-358,8
+352,8
@@
sub parse
$self->{tagtree}=$self->elements_to_tree(\@elements);
if($self->{tagtree})
{
$self->{tagtree}=$self->elements_to_tree(\@elements);
if($self->{tagtree})
{
- ($self->{sqlconditions},
-
$self->{joins}) = $self->{tagtree}->to_sql()
;
+ my ($conditions, @joins)=$self->{tagtree}->to_sql();
+
# print "CONDITIONS(", scalar(@joins), "): ", $conditions, "\n"
;
# print "TREE: ", $self->{tagtree}->print(), "\n";
# print("SQL CONDITION(", scalar(@{$self->{joins}}), "): ",
# $self->{sqlconditions}, "\n");
# print "TREE: ", $self->{tagtree}->print(), "\n";
# print("SQL CONDITION(", scalar(@{$self->{joins}}), "): ",
# $self->{sqlconditions}, "\n");
@@
-387,18
+381,15
@@
sub elements_to_tree
my $thing=pop @$elements;
if($self->is("boolean", $thing))
{
my $thing=pop @$elements;
if($self->is("boolean", $thing))
{
- my $op=$thing;
$right=$self->elements_to_tree($elements);
$right=$self->elements_to_tree($elements);
- if($
op
->{name} ne "NOT")
+ if($
thing
->{name} ne "NOT")
{
$left=$self->elements_to_tree($elements);
}
{
$left=$self->elements_to_tree($elements);
}
- return ID3FS::Path::Node->new($left, $op, $right);
- }
- else
- {
- return ID3FS::Path::Node->new($thing);
+ $thing->left($left);
+ $thing->right($right);
}
}
+ return $thing;
}
# Dijkstra's shunting-yard algorithm
}
# Dijkstra's shunting-yard algorithm
@@
-413,7
+404,7
@@
sub sort_elements
if($self->is("tag", $thing))
{
# Handle tag values by dropping parent
if($self->is("tag", $thing))
{
# Handle tag values by dropping parent
- if(@input && $self->is("tag", $input[0])
+ if(@input && $self->is("tag", $input[0])
)
{
$thing=shift @input;
}
{
$thing=shift @input;
}
@@
-451,7
+442,7
@@
sub expecting_values
my $tail=$self->tail();
if($self->is("tag", $tail))
{
my $tail=$self->tail();
if($self->is("tag", $tail))
{
- return($self->{db}->tag_has_values($tail->
{id}
));
+ return($self->{db}->tag_has_values($tail->
id()
));
}
}
}
}
@@
-461,7
+452,7
@@
sub trailing_tag_id
my $tail=$self->tail();
if($self->is("tag", $tail))
{
my $tail=$self->tail();
if($self->is("tag", $tail))
{
- return($tail->
{id}
);
+ return($tail->
id()
);
}
return undef;
}
}
return undef;
}
@@
-493,9
+484,8
@@
sub is
{
my($self, $type, $thing)=@_;
return 0 unless($thing);
{
my($self, $type, $thing)=@_;
return 0 unless($thing);
- my $ref=ref($thing);
- my $typestr="ID3FS::PathElement::" . ucfirst($type);
- return 1 if($ref eq $typestr);
+ return 0 unless($thing->type());
+ return 1 if($type eq $thing->type());
return 0;
}
return 0;
}
@@
-610,10
+600,9
@@
sub albums
my($self)=@_;
my @ids=();
my $tail=$self->tail();
my($self)=@_;
my @ids=();
my $tail=$self->tail();
- # FIXME: rework PathElements
if($self->is("artist", $tail))
{
if($self->is("artist", $tail))
{
- return $self->artist_albums($tail->
{id}
);
+ return $self->artist_albums($tail->
id()
);
}
my $sql=$self->sql_start("albums.name");
$sql .= ("INNER JOIN albums ON files.albums_id=albums.id\n" .
}
my $sql=$self->sql_start("albums.name");
$sql .= ("INNER JOIN albums ON files.albums_id=albums.id\n" .
@@
-670,11
+659,10
@@
sub album_tracks
sub tracks
{
my($self)=@_;
sub tracks
{
my($self)=@_;
- # FIXME: rework PathElements
my $tail=$self->tail();
if($self->is("artist", $tail))
{
my $tail=$self->tail();
if($self->is("artist", $tail))
{
- return $self->artist_tracks($tail->
{id}
);
+ return $self->artist_tracks($tail->
id()
);
}
elsif($self->is("album", $tail))
{
}
elsif($self->is("album", $tail))
{
@@
-683,9
+671,9
@@
sub tracks
if($self->is("artist", $artist))
{
# should always happen
if($self->is("artist", $artist))
{
# should always happen
- $artist_id=$artist->
{id}
;
+ $artist_id=$artist->
id()
;
}
}
- return $self->album_tracks($artist_id, $tail->
{id}
);
+ return $self->album_tracks($artist_id, $tail->
id()
);
}
my $sql=$self->sql_start("files.name");
$sql .= "INNER JOIN artists ON files.artists_id=artists.id\n";
}
my $sql=$self->sql_start("files.name");
$sql .= "INNER JOIN artists ON files.artists_id=artists.id\n";
@@
-706,7
+694,7
@@
sub filename
my $tail=$self->tail();
if($self->is("file", $tail))
{
my $tail=$self->tail();
if($self->is("file", $tail))
{
- my $id=$tail->
{id}
;
+ my $id=$tail->
id()
;
my $sql=("SELECT paths.name, files.name FROM files\n" .
"INNER JOIN paths ON files.paths_id=paths.id\n" .
"WHERE files.id=?\n" .
my $sql=("SELECT paths.name, files.name FROM files\n" .
"INNER JOIN paths ON files.paths_id=paths.id\n" .
"WHERE files.id=?\n" .
@@
-735,6
+723,9
@@
sub tags_subselect
return "\tSELECT id FROM files AS files_id\n";
}
my $tree=$self->{tagtree};
return "\tSELECT id FROM files AS files_id\n";
}
my $tree=$self->{tagtree};
+ print "UNDEF!!\n" unless($self->{tagtree});
+ use Data::Dumper;
+ print Dumper $tree;
my $parent=$self->trailing_tag_parent();
# print "ELEMENTS: ", join('/', map { $_->{name}; } @{$self->{elements}}), "\n";
my $parent=$self->trailing_tag_parent();
# print "ELEMENTS: ", join('/', map { $_->{name}; } @{$self->{elements}}), "\n";
@@
-786,12
+777,12
@@
sub bare_not_subselect
"\t\tWHERE ");
if(scalar(@tags) > 1)
{
"\t\tWHERE ");
if(scalar(@tags) > 1)
{
- $sql .= ("(t1.parents_id='" . $tags[0]->
{id}
. "' AND t1.id='" .
- $tags[1]->
{id}
. "')");
+ $sql .= ("(t1.parents_id='" . $tags[0]->
id()
. "' AND t1.id='" .
+ $tags[1]->
id()
. "')");
}
else
{
}
else
{
- $sql .= ("(t1.parents_id='' AND t1.id='" . $tags[0]->
{id}
. "')");
+ $sql .= ("(t1.parents_id='' AND t1.id='" . $tags[0]->
id()
. "')");
}
$sql .= "\n\t\tGROUP BY fxt1.files_id\n\t)\n";
return($sql);
}
$sql .= "\n\t\tGROUP BY fxt1.files_id\n\t)\n";
return($sql);
@@
-830,18
+821,18
@@
sub constraints_tag_list
if(defined($lasttag))
{
# print "TAGVAL\n";
if(defined($lasttag))
{
# print "TAGVAL\n";
- push(@tags_vals, [$lasttag, $constraint->
{id}]) if defined($constraint->{id}
);
+ push(@tags_vals, [$lasttag, $constraint->
id()]) if defined($constraint->id()
);
$lasttag=undef;
}
$lasttag=undef;
}
- elsif($self->tag_has_values($constraint->
{id}
))
+ elsif($self->tag_has_values($constraint->
id()
))
{
# print "HASVALUES\n";
{
# print "HASVALUES\n";
- $lasttag=$constraint->
{id} if defined($constraint->{id}
);
+ $lasttag=$constraint->
id() if defined($constraint->id()
);
}
else
{
# print "NOVALUES\n";
}
else
{
# print "NOVALUES\n";
- push(@tags, $constraint->
{id}) if(defined($constraint->{id}
));
+ push(@tags, $constraint->
id()) if(defined($constraint->id()
));
}
}
}
}
}
}