#! /usr/bin/perl use File::Spec; use File::Path; foreach $i (@ARGV) { $dirSize = setGain($i) if (-d $i); } sub setGain { my $dir = shift; return 1 unless (-d $dir); opendir DIR, $dir || return 1; my @files = sort { $a <=> $b} File::Spec->no_upwards(readdir DIR); closedir DIR; my @mp3s = (); my @flacs = (); print "Checking $dir\n"; foreach my $file (@files) { my $path = File::Spec->join($dir, $file); if (-d $path) { setGain ($path); } elsif ($file =~ /.*\.mp3$/) { push @mp3s, $path; } elsif ($file =~ /.*\.flac$/) { push @flacs, $path; } } if (@mp3s != 0) { print "Setting mp3gain in $dir\n"; system("mp3gain", "-p", "-k", "-o", @mp3s); } if (@flacs != 0) { print "Setting metaflac replaygain in $dir\n"; system("metaflac", "--preserve-modtime", "--add-replay-gain", @flacs); } }