Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 10 of 10
  1. #1
    Senior Member
    Join Date
    Oct 2005
    Posts
    7,099

    Scripting MP3Gain on Ubuntu?

    About the last thing that I could do in Windows which I can't do in Ubuntu is MP3Gain post-processing.

    In Windows, I was using MAREO. In Linux, RubyRipper can encode to multiple formats (I'm using FLAC and MP3) but it can't carry out other commands like MAREO can. RubyRipper can carry out CLI commands, but only on the WAV files, not on the MP3s.

    I want to do some custom MP3Gain post-processing, and I'd like to automate it. Currently I have to do this on the command line, drilling down to each album. Kind of tedious when the full path is:

    Code:
    /home/music/Music Library/Jamiroquai/High Times: Singles 1992-2006 (Disc 1)
    Call me lazy, but that's a lot of keystrokes. Also I'd like to "set it and forget it" because since the switch I have forgotten to do this manual post-processing on an album or two.

    Any suggestions? I know there are lots of scripting tools, but they're intimidating for a newbie like me and I'd also have to customize it, i.e. "drill down in the directory until you get to the MP3s".
    Current: SB2, Transporter, Boom (PQP3 - late beta, PQP1 - early beta), SBC (early beta), Squeezebox Radio (PB1 - early beta), Squeezebox Touch (late beta)
    Sold: SB3, Duet

  2. #2
    Ben Sandee
    Guest

    Scripting MP3Gain on Ubuntu?

    On 6/14/07, Mark Lanctot <
    Mark.Lanctot.2s6csz1181835901 (AT) n...limdevices.com> wrote:
    >
    >
    > About the last thing that I could do in Windows which I can't do in
    > Ubuntu is MP3Gain post-processing.



    I used this perl script to generate a shell script, it breaks on special
    characters but it got 90% of my albums when I ran it.

    #!/usr/bin/perl
    while(<>)
    {
    chomp;
    s/([\s\(\)\[\]\'])/\\$1/g;
    print "mp3gain -a $_/*.mp3";
    print "\n";
    }

    Ben


  3. #3
    Ben Sandee
    Guest

    Scripting MP3Gain on Ubuntu?

    On 6/14/07, Ben Sandee <tbsandee (AT) gmail (DOT) com> wrote:
    >
    > On 6/14/07, Mark Lanctot <
    > Mark.Lanctot.2s6csz1181835901 (AT) n...limdevices.com> wrote:
    > >
    > >
    > > About the last thing that I could do in Windows which I can't do in
    > > Ubuntu is MP3Gain post-processing.

    >
    >
    > I used this perl script to generate a shell script, it breaks on special
    > characters but it got 90% of my albums when I ran it.
    >
    > #!/usr/bin/perl
    > while(<>)
    > {
    > chomp;
    > s/([\s\(\)\[\]\'])/\\$1/g;
    > print "mp3gain -a $_/*.mp3";
    > print "\n";
    > }
    >



    Woops, should have added. Run it like this from the root of your music
    directory:

    find . -type d | perl mp3gain.pl

    Ben


  4. #4
    Senior Member
    Join Date
    Apr 2005
    Location
    Portland, OR
    Posts
    212

    My script....

    If you like Perl, I wrote this to set the gain in MP3 and FLAC files.

    http://koldware.com/SlimStuff/MusicUtils/setGain

    Just run it, pointing at the root of your of your music tree or trees, and it will recurse automagically, setting the gain in every mp3 and FLAC file it finds. It does assume a single directory of files are all the same album.
    Code:
      setGain your/music/path/here
    With MP3Gain, you can actually run it as often as you like. MP3Gain won't recalculate the gain if it's already in the file and it's been collected in the same set as the last time. Fairly nice little feature.

    With FLAC files, it will always recalculate the gain for everything. Metaflac doesn't have that nice feature. So you may want to be careful if you're running it with FLAC.

    You may need to install File::Spec and File::Path if they're not already install. Run the following command as root to do that:
    Code:
       perl -MCPAN -e"install File::Path File::Spec"
    Eric
    Last edited by kolding; 2007-06-14 at 14:34.

  5. #5
    Junior Member
    Join Date
    Apr 2007
    Posts
    9
    There is a way to skip previously replaygained flac files, i used the following perl. It will redo replaygain for a directory as album only if any track is missing replaygain tag.

    Code:
    $DIR=$ARGV[0];
    
    sub gettag
    {
      $FILE=$_[0];
      $TAG=$_[1];
      $VAL=`metaflac --show-tag=$TAG \"$FILE\"`;
      chomp $VAL;
      $VAL =~ s/.*=//;
      return $VAL;
    }
    
    if ( ! chdir $DIR ) {
      exit 0;
    }
    
    @FLAC=<*.flac>;
    $num_flac = @FLAC;
    
    foreach $file (@FLAC) {
      $rg = gettag($file,"REPLAYGAIN_TRACK_GAIN");
      if ( !$rg ) {
        last;
      }
    }
    
    if ( $num_flac ) {
      if( !$rg ) {
        print "adding replay gain to $DIR...\n";
        system("metaflac --add-replay-gain *.flac");
      }
    }
    Last edited by myrrh; 2007-06-14 at 23:02.

  6. #6
    Senior Member
    Join Date
    Oct 2005
    Posts
    7,099
    Thanks guys.

    Unfortunately I must be missing something. Ben's script doesn't work at all for me, it just echoes the mp3gain command without actually executing it. It also doesn't appear to drill down directories.

    I got too nervous with kolding's script, installing new CPAN modules involves reconfiguring perl - it started reconfiguring perl in my /home/mark directory and I grew concerned this would prevent SlimServer from using CPAN modules where it expects them to be (definitely not /home/mark), so I aborted.

    Looks like I'll have to research scripts at the Ubuntu forums. Thanks for the pointers though, they gave me some idea of what to do.
    Current: SB2, Transporter, Boom (PQP3 - late beta, PQP1 - early beta), SBC (early beta), Squeezebox Radio (PB1 - early beta), Squeezebox Touch (late beta)
    Sold: SB3, Duet

  7. #7
    Ben Sandee
    Guest

    Scripting MP3Gain on Ubuntu?

    On 6/15/07, Mark Lanctot <
    Mark.Lanctot.2s84gn1181918401 (AT) n...limdevices.com> wrote:
    >
    >
    > Thanks guys.
    >
    > Unfortunately I must be missing something. Ben's script doesn't work
    > at all for me, it just echoes the mp3gain command without actually
    > executing it. It also doesn't appear to drill down directories.



    Hi Mark,

    That's what it's supposed to do. Run it and generate a script, which you
    then run again when you're satisfied with the results. I'm not sure what
    you mean by 'drill down'. It should create a line for each subdirectory of
    the current directory.

    Ben


  8. #8
    Senior Member
    Join Date
    Oct 2005
    Posts
    7,099
    Quote Originally Posted by Ben Sandee View Post
    Hi Mark,

    That's what it's supposed to do. Run it and generate a script, which you
    then run again when you're satisfied with the results.
    Ah, that explains a lot!

    I'm not sure what
    you mean by 'drill down'. It should create a line for each subdirectory of
    the current directory.

    Ben
    I meant go down into each subdirectory and run the command. Now that I know what it does, I think that's what it was doing, but the directory listings didn't look right - there were a fair amount of improper slashes ("\") that the shell might not have accepted.

    I'll try it again on the next album I rip.

    Thanks.
    Current: SB2, Transporter, Boom (PQP3 - late beta, PQP1 - early beta), SBC (early beta), Squeezebox Radio (PB1 - early beta), Squeezebox Touch (late beta)
    Sold: SB3, Duet

  9. #9
    Senior Member
    Join Date
    Apr 2005
    Location
    Portland, OR
    Posts
    212
    Quote Originally Posted by Mark Lanctot View Post
    Thanks guys.
    I got too nervous with kolding's script, installing new CPAN modules involves reconfiguring perl - it started reconfiguring perl in my /home/mark directory and I grew concerned this would prevent SlimServer from using CPAN modules where it expects them to be (definitely not /home/mark), so I aborted.
    Have no fear. Perl is a well designed beasty, and your slimserver will continue to work. CPAN is your friend.

    In fact, if you install the modules as yourself, rather than as root, they won't get installed globally, only in your environment, so if SlimServer runs in a separate account, it will work fine.

    Eric

  10. #10
    Junior Member
    Join Date
    Dec 2005
    Posts
    22
    if your tracks are all at the same level you could use a simple for loop

    e.g.

    Code:
    for i in /home/music/Music\ Library/*/*/*.mp3; do mp3gain -a "$i"; done
    Don't know what the correct syntax for the mp3gain command is I don't use it but you can put in what ever you like.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •