Help - Search - Members - Calendar
Full Version: This script converts APE files to flac files
Hydrogenaudio Forums > Lossless Audio Compression > FLAC
I am all FLAC
This script converts all ape files in the currect directory to flac files.

NOTICE1: It deletes the ape files afterwards.

NOTICE2: During convertion it need ~2x of diskspace of the APE file sizes.

CODE
#!/bin/sh

for f in *ape; do
   mac "$f" "$f.wav" -d
done
rm *ape

rename .ape.wav .wav *.ape.wav

flac --best *wav
rm *wav
perilsensitive
You could save disk space by using a pipe instead of writing the wav files to disk:

CODE

#!/bin/sh

for f in *.ape; do
    mac "$f" - -d | flac --best -s -o "${f%ape}flac" - && rm -f "$f"
done


You could also do the same thing with shntool:

CODE

shntool conv -o "flac flac --best -o %f -" *.ape
rm -f *.ape
I am all FLAC
QUOTE(perilsensitive @ Feb 16 2008, 08:51) *

You could save disk space by using a pipe instead of writing the wav files to disk:

CODE

#!/bin/sh

for f in *.ape; do
    mac "$f" - -d | flac --best -s -o "${f%ape}flac" - && rm -f "$f"
done



Cool! It saves a lot of time as well smile.gif

Does "${f%ape}flac" mean "take the variable $f and replace ape with flac"?

QUOTE(perilsensitive @ Feb 16 2008, 08:51) *

You could also do the same thing with shntool:

CODE

shntool conv -o "flac flac --best -o %f -" *.ape
rm -f *.ape


Nice!! smile.gif Thanks!



perilsensitive
QUOTE(I am all FLAC @ Feb 16 2008, 01:23) *

Does "${f%ape}flac" mean "take the variable $f and replace ape with flac"?


The expression "${foo%bar}" tells the shell to remove the shortest string matching the pattern "bar" from the end of the string stored in variable 'foo' and return the result (this doesn't change what's stored in 'foo', though). So "${f%ape}flac" removes "ape" from the end of the string stored in 'f' (if present), then sticks the string "flac" on the end of what was returned. This has the net effect of replacing the "ape" extension with a "flac" extension, but there are plenty of cases where you'd want to just remove the matching part of the string without replacing it.

Check your shell's manpage for a better and more complete explanation. If you're using bash, it's in the "Parameter Expansion" section.
I am all FLAC
QUOTE(perilsensitive @ Feb 16 2008, 09:41) *

QUOTE(I am all FLAC @ Feb 16 2008, 01:23) *

Does "${f%ape}flac" mean "take the variable $f and replace ape with flac"?


The expression "${foo%bar}" tells the shell to remove the shortest string matching the pattern "bar" from the end of the string stored in variable 'foo' and return the result (this doesn't change what's stored in 'foo', though). So "${f%ape}flac" removes "ape" from the end of the string stored in 'f' (if present), then sticks the string "flac" on the end of what was returned. This has the net effect of replacing the "ape" extension with a "flac" extension, but there are plenty of cases where you'd want to just remove the matching part of the string without replacing it.

Check your shell's manpage for a better and more complete explanation. If you're using bash, it's in the "Parameter Expansion" section.

This is great stuff! Thanks biggrin.gif

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.