key albums off artists too (otherwise we get dylan's unplugged in radiohead's unplugg...
authorIan Beckwith <ianb@erislabs.net>
Sun, 26 Sep 2010 02:43:15 +0000 (03:43 +0100)
committerIan Beckwith <ianb@erislabs.net>
Sun, 26 Sep 2010 02:43:15 +0000 (03:43 +0100)
lib/ID3FS/DB.pm
lib/ID3FS/Path.pm

index 858e068..30510fe 100644 (file)
@@ -280,13 +280,14 @@ sub artist_tracks
 
 sub album_tracks
 {
-    my($self, $album_id)=@_;
+    my($self, $artist_id, $album_id)=@_;
     my $sql=("SELECT files.name FROM files\n\t" .
-            "INNER JOIN albums ON albums.id=files.albums_id\n\t" .
-            "WHERE albums.id=?\n\t" . #AND albums.name <> ''\n\t" .
+            "INNER JOIN albums  ON albums.id=files.albums_id\n\t" .
+            "INNER JOIN artists ON artists.id=files.artists_id\n\t" .
+            "WHERE artists.id=? AND albums.id=?\n\t" .
             "GROUP BY files.name\n");
-    print "ALBUM_TRACKS SQL($album_id): $sql\n";
-    my $result=$self->cmd_rows($sql, $album_id);
+    print "ALBUM_TRACKS SQL($artist_id, $album_id): $sql\n";
+    my $result=$self->cmd_rows($sql, $artist_id, $album_id);
     my @names=map { $_->[0]; } @$result;
     @names = map { s/.*\///; $_;} @names;
     print "TRACKS: ", join(', ', @names), "\n";
@@ -303,7 +304,14 @@ sub tracks
     }
     elsif(ref($constraints[$#constraints]) eq "ID3FS::PathElement::Album")
     {
-       return $self->album_tracks($constraints[$#constraints]->{id});
+       my $artist_id=0;
+       my $artist=$constraints[($#constraints)-1];
+       if(defined($artist) && (ref($artist) eq "ID3FS::PathElement::Artist"))
+       {
+           # should always happen
+           $artist_id=$artist->{id};
+       }
+       return $self->album_tracks($artist_id, $constraints[$#constraints]->{id});
     }
 
     my $main_sql_start=("SELECT files.name\n" .
index 3440780..076b6ca 100644 (file)
@@ -225,7 +225,6 @@ sub parse
                else
                {
                    my $album=ID3FS::PathElement::Album->new($self->{db}, $name);
-                   push(@{$self->{elements}}, $album);
                    if($album)
                    {
                        push(@{$self->{elements}}, $album);