Help - Search - Members - Calendar
Full Version: Monkey's audio to flac in linux
Hydrogenaudio Forums > Lossless Audio Compression > FLAC
zokik
Did anybody already write a shell script for transcoding more files at once? I tried modifying the first script in this thread but since I have no clue about bash scripting I failed.

It would be great if tags were also copied although that would probably require additional program for reading ape tags.

Or if something like Speek's Multifrontend exists for linux?

For now I transcode this way:
mac inputfile.ape - -d | flac -o outputfile.flac -
NumLOCK
Here's a small improvement already:

for filename in *.ape; do mac "$filename" - -d | flac -o "$filename.flac" -; done

This will create .ape.flac files.. You can always use the rename command thereafter (see "man rename").
zokik
Thanks! I'll have to look into bash scripting, it seems like a really handy thing. Now I have this script:
CODE
#!/bin/bash

for filename in *.ape

do
       mac "$filename" - -d | flac -o "$filename.flac" -
done

rename .ape.flac .flac *.ape.flac
jcoalson
QUOTE(NumLOCK @ Sep 1 2003, 03:51 PM)
Here's a small improvement already:

for filename in *.ape; do mac "$filename" - -d | flac -o "$filename.flac" -; done

This will create .ape.flac files..  You can always use the rename command thereafter (see "man rename").

If you're really using bash and not just sh, you can do:

CODE

for filename in *.ape; do mac "$filename" - -d | flac -o "${filename%*.ape}.flac" -; done


then you won't need to rename.

Also, if you can find or write a utility to dump the APE2 tags to a text file in the right format, you can import them later using 'metaflac --import-vc-from'

Josh
zokik
I already found apetag. It does output the ape tags, but some additional formatting should be done before importing tags with metaflac. Here I gave up, maybe I'll try again the next time I need ape2flac transcoding.

Another thing with this program is that it just won't compile on my machine, I get an error and it doesn't even say what kind of error or what is causing it. So I'd have to use the pre-compiled binary of a not well known program downloaded from a not well known place dry.gif
EDIT: I managed to compile apetag on another linux system, can't see why it wouldn't work with suse, maybe it's a gcc 3.3 prerelease issue. It's still no use, it doesn't read any .ape files I have although it does read tags in .mpc files. Possibly I have ape 1.0 tags in .ape files, I think apetag supports only ape 2.0 tags.

I also tried to tag with easytag 0.28.1 (otherwise a great tagging utility). When I configured it, it said it found flac libs, but now it doesn't read nor write tags in flac files. Even the xmms plugin doesn't write flac tags, although it does read them.
plopp
I've just completed migration of all my ape files to flac, and made a little bash script that traverses a path and converts any ape files it finds to flac. It's quite simple, you can set flac parameters if necessary (like compression mode) in the script. Should work for anyone I hope. I ran it on five hard drives simultaneously - two over nfs, and some three days later it was done wink.gif Everything appears to be fine!

There is only one slight bug, which occurs when the filename contains more than one "." .. Someone who is better at bash scripting can probably find out why! smile.gif (hey, it's my first bash script, ok? wink.gif)

You can give it a path as an argument and it will recurse all dirs in that path, or without args it uses the current directory. When working it'll print a tree structure as it goes along.. If it finds an ape file it will appear to stall, but instead will output a single "." for each file it has converted. You'll see when you run it, it's simple..

Have fun!

(copy the below into a text file and save somewhere in your local path)

#!/bin/sh

#
# @(#) ape2flac 0.1 26/09/2003 by Peo Karlsson
#
# Recursively convert APE-files to FLAC.
# Directory recursion adapted from the 'tree' script by Jordi Sanfeliu (see below).
#

#
# @(#) tree 1.1 30/11/1995 by Jordi Sanfeliu (mikaku@fiwix.org)
#
# Initial version: 1.0 30/11/95
# Next version : 1.1 24/02/97 Now, with symbolic links
#

# which extension to look for when browsing the tree
myext="ape"

search () {
xx=0
for dir in *
do
if [ -f "$dir" ]; then
ext=${dir#*.}
base=${dir%%.*}
if [ "$ext" = "$myext" ]; then
echo -n ".";
mac "$dir" - -d | flac - -o "$base.flac" &> /dev/null
rm -f "$dir" &> /dev/null
xx=`expr $xx + 1`
numfiles=`expr $numfiles + 1`
fi
else
if [ $xx > 0 ]; then
echo " -> [$xx files converted]"
xx=0
fi
fi

if [ -d "$dir" ] ; then
zz=0
while [ $zz != $deep ]
do
echo -n "| "
zz=`expr $zz + 1`

done
if [ -L "$dir" ] ; then
echo -n "+---$dir" `ls -l $dir | sed 's/^.*'$dir' //'`
else
echo -n "+---$dir"
if cd "$dir" ; then
deep=`expr $deep + 1`
search
numdirs=`expr $numdirs + 1`
fi
fi
fi
done
cd ..
if [ "$deep" ] ; then
swfi=1
fi
deep=`expr $deep - 1`
}

if [ $# = 0 ] ; then
cd `pwd`
else
cd $1
fi
echo "ape2flac 0.1"
echo
echo "bash script to convert files compressed by Monkey's Audio into FLAC files."
echo
echo "Converting all files in directory = `pwd` and recurse indefinitely."
echo
swfi=0
deep=0
numdirs=0
numfiles=0
zz=0
xx=0

while [ "$swfi" != 1 ]
do
search
done
echo
echo "Summary:"
echo
echo "Total directories = $numdirs"
echo "Total files converted = $numfiles"
echo
exit 0
DrDoogie
Hm, I've always had problems with spaces in my music files.

My workaround is:

oldlfs=$LFS;
LFS=$'\t';
<code to be wrapped here>
LFS=$oldlfs;

But perhaps this isn't necessary when it come to the problem of spaces in the files?

What about &, |, \ and such characters in the filenames?
zokik
I use this simple script:
CODE
#!/bin/bash

while [ -n "$1" ]; do
echo TRANSCODING FILE \""$1"\"
out=$(basename "$1" | sed 's/ape$/flac/')
mac "$1" - -d | flac -o "$out" -
apetag -i "$1" | apetag2vc - - --flac | metaflac --import-vc-from=- "$out"
shift
done

Any ape files you want to convert you pass to the script as arguments (e.g. ape2flac /mnt/music/*.flac) and you will get flac files in your current directory.

If apes are tagged with ape2 tags then tags will also be copied, but you need apetag (see my previous posts) and apetag2vc (I wrote it just to transform output of apetag to vc, if anyone interested let me know) for this. Unfortunately most ape files have ape1 tags and I didn't find any simple cli program to read them. If you don't need tags to be copied just delete or comment out the line starting with "apetag -i ...."

I didn't notice any problems with filenames with spaces, dots, etc. But it does not do any recursive search as plopp's script does.

Edit: corrected the script
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.