Tag Archives: APE

Conquer Giant APE and Giant FLAC

I have already written posts on splitting and converting from either album-length APE files or album-length FLAC files into track-length FLAC files.

(My post on converting APE files; my post on splitting APE files; my post on splitting FLAC files. You will want to go over these other articles if you have not done any of this before as there are some dependencies which you will not likely have installed.)

That was rather satisfying, but I then found that I would locate entire discographies where every album was a single APE or FLAC.  I did not enjoy the prospect of running each command on each pair of files.

That’s why scripting languages exist.  It’s a good thing I bought that BASH book.

Anyway, this script is designed to recursively locate APE, FLAC, and CUE files under a user-supplied root directory; then it runs shntool and cuetag on each APE/FLAC and CUE pair.  (You can read my previous posts linked above for more details about how these two commands work.)

It even cleans up after itself.  Since it deletes not only the temporary files it creates but also all the APE, FLAC, and CUE files it uses, you will want to pay close attention when the script tells you it is about to clean up all those files.  If you tell it to proceed (by hitting ENTER) without checking its work all those files will be deleted.  As such you should work from copies and you should check that it did what you wanted it to do before hitting ENTER when it asks about cleaning up all files.

Feel free to suggest any improvements.  I hope you find that it works well and improves your lives.

One important thing to note is that it is not an intelligent script.  It cannot determine for you whether a given APE or FLAC file is actually album length.  It assumes that you are offering it a folder (with or without sub-folders) which contains only album-length APE or album-length FLAC files with an accompanying CUE file (one matching pair per containing folder).

Sometimes a cue file will be formatted incorrectly or have some other issue.  Sometimes they can be fixed by opening them in a text editor.  Probably they can always be fixed in a text editor, but it might be difficult to determine what’s wrong with the CUE file.  If a CUE files has issues you will see errors on the command line (if you are staring at your monitor) and the album-length file will not be split/tagged.  You’ll have to work on that pair separately, but since you are working from copies it won’t matter if they get deleted.

If you throw something unusual at it, it’s hard to imagine how it might behave.  It’s likely not dangerous but you should always work from copies and preserve the originals until you are satisfied.

##
#!/bin/bash
# covert APE/FLAC albums to FLAC tracks recursively
# by JamesIsIn from JamesIsIn.com
# Do something nice today.

## gather information

# obtain directory in which to work

printf "\nHello.\n\n"
read -e -p "Please provide the root folder under which I will work recursively: "
if [ -d "$REPLY" ]; then
printf "\nI have confirmed this is a directory.\n\n"
directory="$REPLY"
else
printf "\nI cannot confirm this is a directory.\n\n"
echo "$REPLY"
exit 1
fi

# number, performer, and track names

printf "There are two formatting options for file naming (assuming the cue contains correct information):\n\n"
printf "01 – Track Name.flac\n"
printf "01 – Performer Name – Track Name.flac.\n\n"
read -p "Do you want to include the performer name in the file names (this is only recommended for multiple-artist albums)? [Y or N]: "
if [ "$REPLY" = "Y" ]; then
printf "\nOk, I'll include performer names: 01 – Performer Name – Track Name.flac\n\n"
trackname="%n – %p – %t"
elif [ "$REPLY" = "y" ]; then
printf "\nOk, I'll include performer names: 01 – Performer Name – Track Name.flac\n\n"
trackname="%n – %p – %t"
else [ "$REPLY" = "[Nn]" ];
printf "\nOk, I won't include performer names: 01 – Track Name.flac\n\n"
trackname="%n – %t"
fi

printf "\n\nLet's get to work.\n\n\n"

## do the work

# parse files into respective arrays recursively

find "$directory" -type f -name \*.[Aa][Pp][Ee] -o -name \*.[Ff][Ll][Aa][Cc] > /tmp/whyme

declare -a albumfind
let i=0
while read albumline; do
albumfind[$i]=$albumline
((i++))
done < /tmp/whyme

find "$directory" -type f -name \*.[Cc][Uu][Ee] > /tmp/whyme2

declare -a cuefind
let i=0
while read cueline; do
cuefind[$i]=$cueline
((i++))
done < /tmp/whyme2

# follow array counts

printf "\n\nCounts are as follows. There are "${#albumfind[@]}" albums and "${#cuefind[@]}" cues. Your albums ought to equal your cues. If these counts are not as expected, please inspect the contents of the folder you provided before proceding or re-run the script and select a different folder.\n\n"
read -p "Press <ENTER> to coninue. "

# split apes and flacs; hide album files

for (( i=0 ; i < ${#albumfind[@]} ; i++ )) ; do
# path is cue iteration less file name
albumfolder="${cuefind[i]%/*.*}"
shnsplit -d "$albumfolder" -o flac -f "${cuefind[i]}" -t "$trackname" "${albumfind[i]}" ;
mv "${albumfind[i]}" "${albumfind[i]}".hideme ;
done

# remove 00 files

find "$directory" -type f -name 00\*.[Aa][Pp][Ee] -o -name 00\*.[Ff][Ll][Aa][Cc] > /tmp/whyme3

declare -a deadfiles
let i=0
while read deadline; do
deadfiles[$i]=$deadline
((i++))
done < /tmp/whyme3

for (( i=0 ; i < ${#deadfiles[@]} ; i++ )) ; do
mv "${deadfiles[i]}" "${deadfiles[i]}".hideme ;
done

# tag files

for (( i=0 ; i < ${#cuefind[@]} ; i++ )) ; do
# path is cue iteration less file name
albumfolder="${cuefind[i]%/*.*}"
cuetag "${cuefind[i]}" "$albumfolder"\/*.flac
mv "${cuefind[i]}" "${cuefind[i]}".hideme ;
done

## clean-up

printf "\n\nI have completed all operations to the best of my ability.\nI will now clean up all files.\n\nPlease ensure you are satisfied with the state of things before you continue."
printf "\n\nPlease note: I am about to delete all the album-length files I believe I have used."
read -p "Press <ENTER> to coninue (Ctrl-c will abort clean-up). "

# remove temp files, hideme files, and unset all variables

find "$directory" -type f -name *.hideme > /tmp/whyme4

declare -a hidemes
let i=0
while read hidelines; do
hidemes[$i]=$hidelines
((i++))
done < /tmp/whyme4

for (( i=0 ; i < ${#hidemes[@]} ; i++ )) ; do
rm "${hidemes[i]}" ;
done

rm /tmp/whyme*
unset

exit

##

Have fun with that.

Share

Little Apes to FLAC Files

You may come across individual APE files which you would like to convert to FLAC files.  This can be especially useful if you have an album FLAC and an accompanying CUE file and you are having trouble getting the APE to burn correctly.

There is a fairly simple tool for dealing with this conversion.  As fortune would have it this tool will also manage conversions to and from ALAC, SHN, TTN, and WAVE files.  How can they pack so much fun into such a small package?  Now it’ll be that much easier to clean your collection up and keep everything tidy: flacflacflac.

Ok, so you’ll need—and if you’ve been following along here you already have—the MAC (Monkey Audio Codec).

Next you’ll need to get something called apeinfo.   There exist both 32 and 64 bit versions so be sure you get the proper version for whichever Ubuntu you are running.  You will find them here.  You will want to change the name of the file you download to merely apeinfo (so remove the _32 or _64) or it won’t work when called up by the next tool.

The next tool being known as convtoflac.  You may find that here.

Download both of your files and they all gets stuck into /usr/local/bin.

I downloaded each of these to my desktop and then used sudo to copy them into /usr/local/bin.  Make certain you have given them execute permissions (set the execute bit).  By storing them in /usr/local/bin I am sure they are in my command path (basically those places your system looks when you type a command) and they are ready to use.  Here is the command you need to move the apeinfo file from the Desktop to /usr/local/bin:

sudo mv /home/[usename]/Desktop/apeinfo /usr/local/bin/apeinfo

You can copy and paste that line and make the necessary substitutions for your system, download location, and specific file.

Once you have these installed correctly you are ready to use the tools to make conversions.  I have written a small simple script for making all of this work together.  If you make my script executable and place it  in your /usr/local/bin you can merely call the whole thing up by typing the name of the command (whatever you decide to name your version of my script) in your terminal.  I named my script Ape2Flac.sh.

##
#!/bin/bash
# by JamesIsIn from JamesIsIn.com
# Do something nice today.

#  Ape2Flac.sh

#  also requires apeinfo and convtoflac
#  http://jamesisin.com/a_high-tech_blech/?p=1335

for i in *.ape
do convtoflac.sh "$i"
done

##

This method will preserve any existing tags.

To fire it up, navigate into the folder in which you have the APE files and run my script (by typing its name into the command line).  It’s that easy.

See, nothing to fear from the command line.

Happy hunting.

Share

Make a Big APE into Several Small, Tagged FLAC Files

You may recall with great excitement my post on splitting and tagging album length FLAC files into track length FLAC files.  It may come to pass that you find yourself staring at an album length APE file.

What?  What the hell is an APE file?

In short, some folks decided “hey, what the world needs is another media player and it’s very own lossless codec”.  In their defense, MediaMonkey looks like a pretty cool application (say “iTunes killer”), and it does support FLAC and OGG so I don’t dispise it.  Nonetheless, it is my advice to avoid specialized and proprietary codices wherever possible.  Unfortunately Monkeys, this means no APE files.

As fate would have it, if you are already set up to split and tag an album FLAC, you are nearly ready to do the same for an album APE.  You just need the MAC (monkey audio codec).

You have two choices.  This codec isn’t part of what Canonical normally provides, so you can either add a repository which includes it or you can download the codec directly.  I tend to prefer adding a repository, but the codec can be downloaded in this package.

http://members.iinet.net.au/~aidanjm/mac-3.99-u4_b3-1_i386.deb

(If you choose to download the .deb package, double-clicking on it once you have downloaded it and your system will run the installation.)

For those of you, like me, who prefer to add a repository, the Eudoxos repositories include MAC, so we can add this one.

http://ppa.launchpad.net/eudoxos/ubuntu yourubuntuversion main

Once you have added that repository Monkey Audio will appear in Synaptic.  To install the Monkey Shite open Synaptic and look for Monkey Audio. (Please note that newer editions of this repository no longer carry the MAC, yet I am using the repo for 8.10 in my 10.04 machine successfully.)

Now let’s get to the meat of it.  I have grown lazy and tend to rename my FLAC, APE, and cue files to the letter a, so my commands look like this:

shnsplit -o flac -f a.cue -t “%n – %t” a.ape

cuetag a.cue *.flac

(Please note there may be a copy and paste problem here.  The quotation marks are different.  So when you grab the part -t “%n – %t” you will have to replace the quotation marks by typing them afresh.  Failure to do so will yield an error—shnsplit: error: need exactly one file to process.  Alternatively you may copy from the  code section below.)

[CODE=”BASH”]##

# Here are the two commands you will need

shnsplit -o flac -f a.cue -t “%n – %t” a.ape

# Note: you may substitute “%n – %a – %t” if you want artist names in your file names

# now you may move or remove the album APE]

cuetag a.cue *.flac

##[/CODE]

Unlike splitting a FLAC file into smaller flac files, you don’t necessarily have to send the album length APE to the trash (or remove it’s file extension) between performing these two commands.  But you can.

If this isn’t strait forward, you may want to read through my previous post to sort out the details of the conversion process and then come to this post for the APE specific information.

Thanks to this post for some information.

Share