View previous topic :: View next topic |
Author |
Message |
Gilbo Tux's lil' helper
Joined: 03 Apr 2004 Posts: 127 Location: Halifax, NS
|
Posted: Sat Apr 09, 2005 1:38 am Post subject: Recursively processing files with metaflac. |
|
|
I need to run through a directory structure and add replaygain information to all the flac files in the directory tree.
The command to process flac files and add replaygain tags is:
Code: | metaflac --add-replay-gain myfiles |
I tried piping the output of find to metaflac but it's not working. I'm sure this was a terrible ideas. My bash skills are weak:
Code: | find /home/music/* *.flac | metaflac --add-replay-gain |
The help of anyone with scripting knowledge, who could expand on my laughable attempt, would be greatly appreciated. Cheers. |
|
Back to top |
|
|
nephros Advocate
Joined: 07 Feb 2003 Posts: 2139 Location: Graz, Austria (Europe - no kangaroos.)
|
Posted: Sat Apr 09, 2005 2:17 pm Post subject: Re: Recursively processing files with metaflac. |
|
|
Gilbo wrote: | Code: | find /home/music/* *.flac | metaflac --add-replay-gain |
|
Try it this way: Code: | find /home/music/* -name "*.flac" -exec metaflac --add-replay-gain {} \; |
or:
Code: | cd /home/music/
for f in /home/music/*flac
do
metaflac --add-replay-gain $f
done |
or
Code: | cd /home/music/
ls *flac | xargs metaflac --add-replay-gain |
The pipe you did would pass the list of filenames (the text) to metaflac which cannot interpet them as path info this way.
consider:
ls bar* | grep "foo"
versus
grep "foo" bar*
The first command would produce all the filenames starting with bar and the "foo" in the filename, the second would search for the string foo in all files starting with bar.
Thats why you need either xargs ot the -exec option to find.
Also, find needs the -name option to match filename globs.
HTH. _________________ Please put [SOLVED] in your topic if you are a moron. |
|
Back to top |
|
|
Gilbo Tux's lil' helper
Joined: 03 Apr 2004 Posts: 127 Location: Halifax, NS
|
Posted: Tue Apr 12, 2005 5:16 pm Post subject: |
|
|
Thanks a lot nephros for the info. However, I can't get your methods to work. Their certainly far closer than my uneducated attempt, and I understand what you mean about metaflac not being able to take find's output through the pipe.
Option 1:
Code: | find /home/music/* -name "*.flac" -exec metaflac --add-replay-gain {} \; |
Gives:
Code: | -bash: syntax error near unexpected token `(' |
Without the brackets it gives, repetitively, like it is indeed going through all the files in the subdirectories recursively:
Code: | ERROR: you must specify at least one FLAC file;
metaflac cannot be used as a pipe |
followed by the contents of the short help file.
Option 2:
Code: | cd /home/music/
for f in /home/music/*flac
do
metaflac --add-replay-gain $f
done |
Gives:
Code: | /home/music/*flac: ERROR: reading metadata, status = "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE" |
Option 3:
Code: | cd /home/music/
ls *flac | xargs metaflac --add-replay-gain |
Gives:
Code: | ERROR: you must specify at least one FLAC file;
metaflac cannot be used as a pipe |
followed by the short help, but only once (unlike the first option which cycles through a whole bunch of files before finishing. |
|
Back to top |
|
|
Gilbo Tux's lil' helper
Joined: 03 Apr 2004 Posts: 127 Location: Halifax, NS
|
Posted: Tue Apr 12, 2005 5:18 pm Post subject: |
|
|
The second error message is a little strange, because it seems like it hit what it thought was a good file, and then realized it wasn't. Some of the subdirectories end in .flac . Could this be messing it up?
I just realized that it only gives that message once and then exits, and that it wouldn't be hitting one of those *.flac directories first, so I don't think that's the problem. |
|
Back to top |
|
|
transienteagle Apprentice
Joined: 24 Dec 2003 Posts: 190 Location: UK
|
Posted: Wed Apr 13, 2005 10:51 am Post subject: |
|
|
Gilbo,
I think that the code of Nephros as shown below is good
Code: | cd /home/music/
for f in /home/music/*flac
do
metaflac --add-replay-gain $f
done |
The only time I think that it would not work is if you did not have any files ending in flac in the directory; in which case the loop still runs one time but $f will contain /home/music/*flac as its input to metaflac.
A question for you; do your metaflac files end in flac??
rgds
TE |
|
Back to top |
|
|
|