Tag Archives: flac

Conquer 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.

A couple of things have changed since I first wrote this script and article.  First, the script no longer accepts ape files as input.  You will want to convert them directly into flac files before splitting.  This is very easy and at some point I’ll add notes on how to do that.  Second, the script no longer lives here because it’s easier for me to maintain and share them over at GitHub.

splitFLAC.sh at GitHub

Have a great time!


Update to My Renaming Script


I have vastly improved my renaming script and published it to GitHub for your convenience.


Original article:

A while back I wrote a post on renaming FLAC files to include their associated disc numbers.  For example, if you have a file from disc 1 named “01 – Track Name.flac” my script would change it to “01.01 – Track Name.flac”.

This updated version of the script allows the user to enter the path to the folder needing files renamed and the associated disc number.

I think this is a slightly simpler method than my previous method for using this script.

Here is the current script:

# Please refer to note at top of article for direction to current script.

This version also handles FLAC extensions in any case (flac=FLAC=FlAc &c).

If I make any updates, I’ll likely just change this post.  As such, I should say that this current version is current as of 8 March 2010.

Have fun with that.


Little Apes to FLAC Files

The below article remains for archive purposes.  You can now easily convert APE directly to FLAC with ffmpeg.


# One command per ape... 

ffmpeg -i inputname.ape outputname.flac 

# ... in a loop cd into containing folder and... 

for apeFile in *.ape ; do 
    ffmpeg -i "${apeFile}" "${apeFile%\.ape}.flac" 


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.

# 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"


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.


Make a Big APE into Several Small, Tagged FLAC Files

The below article remains for archive purposes.  You can now easily convert APE directly to FLAC with ffmpeg.


# One command per ape... 

ffmpeg -i inputname.ape outputname.flac 


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.


(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:


# 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


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.


FLACking Week

Well, as you probably know by now I’ve been preparing for building a music server so that I can archive my substantial CD collection into cases in the basement.  I have spent the last week ripping CD’s into .flac files and stowing those on an extra 500GB drive I have temporarily mounted in my main Ubuntu desktop machine.

I have torn through most of my collection.  There is a stack of maybe 30 classical CD’s I haven’t done yet, and there are a few straglers which I will have to enter the information by hand (since they are apparently obscure enough not to be represented in these on-line repositories of CD information).  Once done with these my entire store-bought collection (in the neighborhood of 750 ablums or maybe 850 discs) will be sitting on this drive coming in around 235GB.

This has kept me rather busy, even if it’s been in a fundamentally mechanical manner.

On a side note, I recommend that every one of you goes out and joins one of the various database sites for music.  I have joined Music Brainz for no real preferential reason.  There are others; many others.  (Post your favorite in the comments.)  Pick one (or more) and join.  And then login and fix some of your favorite album information.  Currently, though these sites are great repositories of information about albums, they are filled with silly little errors: track names which include the artist name, misspelled band names, miscapitalizations of all kinds (Art of Noise; not Art Of Noise—only important words get caps in English), &c.  I think they must use bots to farm this data initially, and then they rely on human intervention for the drift toward perfection.  Just a theory, mind you.

But seriously, you don’t have to be a programmer to help out the spirit of open source.

Anyway, you’ll likely see some more posts about this digital music adventure as I get time to write them.  I have already posted a couple.

Man, it sure is nice to have my entire music collection never more than a couple of mouse clicks away.

Happy hunting.


Out of My Shell and into My Collection

As you may have heard, I’m building a music server for my home (aka my local network).  I’m rippin’ dem discs down to .flac files and stowing dem on a phat drive.  Caught between geek and gangster, I’m having a good time.

I am using Sound Juicer to squeeze my CD’s into flacs.  You can read about my encoding woes and solutions here.

Sound Juicer: Applications —> Sound & Video —> Audio CD Extractor

One thing about using Sound Juicer is that it likes to put all the files for an album or boxset into a single folder with the name of that album or boxset (under a folder with the name of the person or band or whatever).  That works out fine if you rip single albums (like Pink Floyd’s Meddle, for instance).  It creates files with the track numbers (optional, but I like it) and track names:

01 One Of These Days.flac

As you can see, that’s pretty straight forward.  Where I run into trouble is when I rip a boxset, such as The Immortal Soul of Al Green.  This is a four disc set.  Sound Juicer wants to create a folder called “The Immortal Soul of Al Green” and put all of the tracks into that folder.  That means I have four track ones and four track twos…

Ack!  What a mess that is.

So I did some hunting around the web and got some help from this blogger here, and I wrote a script that would do me a favor.

I don’t really want to create folders called “The Immortal Soul of Al Green CD1” and “The Immortal Soul of Al Green CD2” all the way down the line for each double album and boxset I encounter.  Instead I will be satisfied by prepending each track number with the corresponding disc number for that particular album.  Single albums I will not change.

So, for the album “The Immortal Soul of Al Green” I will run a script on those files for disc three such that the files will change as follows:

01 Take Me To The River.flac —> 03.01 Take Me To The River.flac

This tells me that this song is the first track on the third disc of this set.  Using this method keeps all of the songs from this boxset in one folder (called “The Immortal Soul of Al Green”) under the folder in my collection called Al Green.  Further, when I look in this folder all of the songs are in order.  Very convenient and easy to comprehend.

At first I was doing this by renaming each file as they were ripped.  Lame.  Oh, so very lame.  Curdled lameness.

(I have updated this renaming script.  You can find that new version here.)

Here is the script I settled upon thanks to a little research and some kind coders far and wide:

for filename in *.flac
mv "$filename" ../Changed/03."$filename"
echo $filename changed | tee -a /home/[username]/Desktop/Changed/logfile

As you may guess, this is the script for changing the names of the songs from CD 3.  Remember to use your actual username.  To make the scripts necessary for other CD’s simply change the 03 to whatever disc number you are interested in (01 or 02 or whatever).  Put this into an empty file and save it.  I saved mine as ChangeScript.sh (the sh file extension merely indictates it’s a shell script).  Name yours whatever you want.  (The line beginning echo is totally superfluous to the actions desired and so can be omitted, but it allows the script to tell you what it’s doing and so it can be very handy.)  After you have saved this file you will want to alter the permissions of the file and allow execution:

  1. Right-click the .sh file you created and saved
  2. Choose Properties from the context menu which appears
  3. On the Properties dialog select the Permissions tab
  4. Check the “Allow executing file as program” box

Here is the setup I was using in which this script was functioning.  I had a folder on my Desktop for each disc number (01-08) and after a disc would rip I would drop all the files for that disc into the appropriate folder.  I had a copy of the script in each folder (each using the corresponding disc number 01-08).  Open a command prompt (Applications —> Accessories —> Terminal) and get to the folder where you plan to do this work—I used my Desktop (enter: cd ~Desktop).

In a command prompt after dropping all the files for a disc into the correct folder I would perform the following actions to get into that folder and run the script (you won’t need the ../ the first time):

  • cd ../01
  • ChangeScript.sh

This would put all of the files into another folder on my Desktop which I called Changed.  (It also creates a logfile in Changed in case that interests you.)  Once I had changed all the discs for a set I would move the files from Changed into my library.  Then I would move on to the next set.

Totally confusing?  You’ll get there.  Hang on tight.

Hope this has been helpful.