You are not logged in.
Pages: 1
I'm trying to write a bash script to add Replay Gain to my FLAC collection, and I think I've hit a wall with a seemingly simple bash task. You don't need to know anything about Replay Gain or FLAC to help me, just a working knowledge of bash scripting.
Okay, so if I were to do this manually for each album (it has to be on a per-album basis, not per-track and not my whole collection at the same time), here's what would happen:
cd album_directory
metaflac --add-replay-gain *.flac
And that's it. Pretty simple, but I'm having a hard time figuring out how to cd into each directory and run a command. (It really is a shame that flac isn't as smart as vorbisgain, which performs this task trivially.) Here's my script so far:
#!/bin/bash
# Script to add replaygain tags to flac files
# (The current flac encoder cannot guess albums by folder like vorbisgain)
top_dir=/media/cuboid/music/
function gain {
cd && metaflac --add-replay-gain *.flac
}
find $top_dir -mindepth 2 -type d -print0 | xargs -0 gain
Obviously, the gain function is where I need help. I greatly appreciate it.
Last edited by fflarex (2008-01-28 04:56:09)
Offline
Shouldn't this do? metaflac --add-replay-gain */*.flac
Offline
Well, the album folders are 2 levels in, not 1, but I'm not sure I understand what that does.
Would that execute metaflac for each folder individually or would it do my entire collection at the same time (which would mess up the albumgain tags)?
Offline
Ahh I see the complication now (I don't have that program/not familiar with gain either).
So let's say it looks like
$topdir/genre_piano/album_foobar/song_{1..10}.flac
for album in */*; do ([ -d "$album" ] && cd "$album" && metaflac --add-replay-gain *.flac); done
the subshell "(...)" should make cd'ing back redundant.
Offline
Well, I'm not sure why that works but I'll try it and see. I don't understand why you don't need to cd back (although I can see how if you did cd back each time, it would just keep going to the same folder and not get anywhere).
EDIT: nvm, I get it now. I'm about to find out if it works...
Last edited by fflarex (2008-01-28 04:36:06)
Offline
Hallelujah! Thanks, it works perfectly... now I just need to wait like 16 hours or something crazy like that for it to finish running.
EDIT: my favorite part of the whole thing is that it works in alphabetical order... so many programs seem to work in order of creation date, giving me next to no clue how far along it is.
Last edited by fflarex (2008-01-28 04:52:38)
Offline
If it's consuming too much CPU, you can always renice it.
Offline
No, there's no way for it to avoid using lots of CPU. It analyzes the audio of every single song.
EDIT: I misunderstood what you just said. I've never used renice before. In other news, I think I've edited more of my posts in this single thread than all my other posts combined.
Last edited by fflarex (2008-01-28 05:04:47)
Offline
But that doesn't mean your Firefox has to become unresponsive. A pgrep firefox and renice -8, and pgrep "for album" and renice +10 might be just the cure it wants.
Offline
The other day I was playing Counter Strike Source when a new wine version was released.
I always play CSS at nice -8, and I compiled the new version with nice +10. Both are very consuming processes, but I didn't notice a thing in-game. I thought that was pretty cool.
Offline
it's just scheduling priority. don't see how games can be affected. only -20 and 20 will make significant difference. used to compile on gentoo with -10 though..a good compromise.
I need real, proper pen and paper for this.
Offline
Pages: 1