+sub gather_tags
+{
+ my($path, $file)=@_;
+ my @tags=$file->tags();
+ @tags=map { join('/', grep { defined; } @$_); } @tags;
+ @tags=ID3FS::AudioFile::uniq(@tags);
+ $file_tags{$path}=\@tags;
+}
+
+sub summarize_tags
+{
+ my @all_tags=ID3FS::AudioFile::uniq(map { @$_; } values(%file_tags));
+
+ # group tags by directories
+ my %dir_tags=();
+ my @dirs=map { s/(.*)\/.*/$1/; $_; } keys %file_tags;
+ @dirs=ID3FS::AudioFile::uniq(@dirs);
+ for my $tag (@all_tags)
+ {
+ DIR: for my $dir (@dirs)
+ {
+ for my $file (keys %file_tags)
+ {
+ next unless(@{$file_tags{$file}});
+ next unless($file =~ /^$dir/);
+ next DIR unless(grep { $_ eq $tag; } @{$file_tags{$file}});
+ }
+ push(@{$dir_tags{$dir}}, $tag);
+ }
+ }
+
+ # remove dir tags from files
+ for my $path (keys %dir_tags)
+ {
+ for my $file (keys %file_tags)
+ {
+ next unless($file =~ /^$path/);
+ $file_tags{$file} = [ ID3FS::AudioFile::list_remove(
+ $dir_tags{$path},
+ $file_tags{$file}) ];
+ }
+ }
+
+ # find common tags
+ my @common_tags=();
+ OUTER: for my $tag (@all_tags)
+ {
+ for my $taglist (values(%dir_tags))
+ {
+ next OUTER unless(grep { $_ eq $tag; } @$taglist);
+ }
+ push(@common_tags, $tag);
+ }
+
+ # remove common tags from %file_tags
+ for my $filename (keys(%file_tags))
+ {
+ next unless(@{$file_tags{$filename}});
+ $file_tags{$filename}= [ ID3FS::AudioFile::list_remove(\@common_tags,
+ $file_tags{$filename}) ];
+ }
+
+ # remove common tags from %dir_tags
+ for my $path (keys(%dir_tags))
+ {
+ next unless(@{$dir_tags{$path}});
+ $dir_tags{$path}= [ ID3FS::AudioFile::list_remove(\@common_tags,
+ $dir_tags{$path}) ];
+ }
+
+# print "ALL: ", join(', ', @all_tags), "\n";
+ print "Common tags: ", join(', ', @common_tags), "\n";
+# print "PER-DIR:\n";
+ for my $path (sort keys %dir_tags)
+ {
+ next unless(@{$dir_tags{$path}});
+ print "$path: ", join(', ', @{$dir_tags{$path}}), "\n";
+ }
+
+# print "PER-FILE: \n";
+ for my $filename (keys(%file_tags))
+ {
+ next unless(@{$file_tags{$filename}});
+ print "$filename: ", join(', ', @{$file_tags{$filename}}), "\n";
+ }
+}
+