};
}
+my %info = (
+ '.flac' => \&flacinfo,
+ '.mp3' => \&mp3info,
+ '.ogg' => \&vorbisinfo,
+ '.oga' => \&vorbisinfo,
+ '.mp4' => \&mp4info,
+ '.aac' => \&mp4info,
+ '.m4a' => \&mp4info,
+);
+
sub normalizer{
"$_[0]|".(stat $_[0])[9]
}
sub make_fragment{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ }
sub run {
+ my %info = %info;
if ($cache) {
tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644;
- memoize $_, NORMALIZER => \&normalizer, LIST_CACHE => 'MERGE', SCALAR_CACHE => [HASH => \%cache] for qw/flacinfo mp3info vorbisinfo mp4info/;
+ $info{$_} = memoize $info{$_}, INSTALL => undef, NORMALIZER => \&normalizer, LIST_CACHE => 'FAULT', SCALAR_CACHE => [HASH => \%cache] for keys %info;
}
my %files;
for my $file (@ARGV) {
- my $info;
- $info = thaw scalar flacinfo $file if $file =~ /\.flac$/i;
- $info = thaw scalar mp3info $file if $file =~ /\.mp3$/i;
- $info = thaw scalar vorbisinfo $file if $file =~ /\.og(?:g|a)$/i;
- $info = thaw scalar mp4info $file if $file =~ /\.mp4|\.aac|\.m4a$/i;
- next unless defined $info;
- my $basename = fileparse $file, '.flac', '.mp3', '.ogg', '.oga', '.mp4', '.aac', '.m4a';
+ my ($basename, undef, $suffix) = fileparse $file, keys %info;
$files{$basename} //= [];
- push @{$files{$basename}}, $info;
+ push @{$files{$basename}}, thaw scalar $info{$suffix}->($file);
}
my $ht=HTML::Template::Compiled->new(