Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Recursively processing files with metaflac.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Gilbo
Tux's lil' helper
Tux's lil' helper


Joined: 03 Apr 2004
Posts: 127
Location: Halifax, NS

PostPosted: Sat Apr 09, 2005 1:38 am    Post subject: Recursively processing files with metaflac. Reply with quote

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
View user's profile Send private message
nephros
Advocate
Advocate


Joined: 07 Feb 2003
Posts: 2139
Location: Graz, Austria (Europe - no kangaroos.)

PostPosted: Sat Apr 09, 2005 2:17 pm    Post subject: Re: Recursively processing files with metaflac. Reply with quote

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
View user's profile Send private message
Gilbo
Tux's lil' helper
Tux's lil' helper


Joined: 03 Apr 2004
Posts: 127
Location: Halifax, NS

PostPosted: Tue Apr 12, 2005 5:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gilbo
Tux's lil' helper
Tux's lil' helper


Joined: 03 Apr 2004
Posts: 127
Location: Halifax, NS

PostPosted: Tue Apr 12, 2005 5:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
transienteagle
Apprentice
Apprentice


Joined: 24 Dec 2003
Posts: 190
Location: UK

PostPosted: Wed Apr 13, 2005 10:51 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum