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:
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.Code:/home/music/Music Library/Jamiroquai/High Times: Singles 1992-2006 (Disc 1)
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".
Results 1 to 10 of 10
Thread: Scripting MP3Gain on Ubuntu?
-
2007-06-14, 08:41 #1Senior Member
- Join Date
- Oct 2005
- Posts
- 7,099
Scripting MP3Gain on Ubuntu?
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
-
2007-06-14, 08:51 #2Ben SandeeGuest
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
-
2007-06-14, 08:53 #3Ben SandeeGuest
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
-
2007-06-14, 14:19 #4
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.
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.Code:setGain your/music/path/here
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:
EricCode:perl -MCPAN -e"install File::Path File::Spec"
Last edited by kolding; 2007-06-14 at 14:34.
-
2007-06-14, 22:57 #5Junior 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.
-
2007-06-15, 07:38 #6Senior 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
-
2007-06-15, 08:31 #7Ben SandeeGuest
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
-
2007-06-15, 08:38 #8Senior Member
- Join Date
- Oct 2005
- Posts
- 7,099
Ah, that explains a lot!
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'm not sure what
you mean by 'drill down'. It should create a line for each subdirectory of
the current directory.
Ben
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
-
2007-06-15, 14:42 #9
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
-
2007-06-23, 02:44 #10Junior 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.
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.Code:for i in /home/music/Music\ Library/*/*/*.mp3; do mp3gain -a "$i"; done

Reply With Quote


