replaygain.pl

#!/usr/bin/perl -w

use strict ;

my $file = $ARGV[0] || die ;

if ($file =~ /\.mp3$/i) {

  my $out = `nice -n 20 mp3gain "$file" 2> /dev/null` ;
  $out =~ /Recommended "Track" dB change: (.*)$/m || die ;
  print "annotate:replay_gain=\"$1 dB\":$file\n" ;

} elsif ($file =~ /\.ogg$/i) {

  system("nice -n 20 vorbisgain -f \"$file\" \
          2>/dev/null >/dev/null") ;
  my $info = `ogginfo "$file"` ;
  $info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/ || die ;
  print "annotate:replay_gain=\"$1 dB\":$file\n" ;

} else {

  print "$file\n" ;

}
Download