Partition 36 Blog
Encoding Files, Again

About six months ago, I wrote about a Python script I made that made my life easier when it came to encoding files.  Well I made some simple changes and updated it to v1.1.

Changes include:

  • Ability to override the default tags
  • Command line option to change the Ogg Vorbis quality
  • Somewhat cleaner output
  • Verbose output for debugging or embedding this in scripts
  • The program can optionally create the destination folders if they don’t exist
  • Better handling of directories
  • “Dry Run” mode to see what would happen without actually encoding anything
  • Other minor changes and bug fixes
  • The script can live in any arbitrary location (the previous one might have been able to as well, but I never tested it)
  • License changed to GPL v3

The big one is probably the ability to override tags, which is what I was needing specifically.  Eventually I’ll add the ability to check date stamps on files and only encode files older than what gets specified.  But not tonight :)

Again, this is just a small bit of insight into how I handle my music.  It may not seem like much, but having this script actually saves me a lot of time and headaches.  You can download the script here (right-click and Save As).  To run, you need Python 2.6 or 2.7; and lame, flac, oggenc, and id3v2 all located somewhere in your PATH.

I run this on Slackware Linux.  I highly doubt this script will run correctly in Windows, but you can try.  It should work on Mac OS X, but I haven’t tested it.

Encoding Files

Warning!  Geeky post ahead!  I wrote this post to offer some insight into how I handle the preparation of the .mp3 and .ogg files that I use on the website, as well as the .flac files I keep for archives.  So, it’s a bit jargon-y.  Sorry.  But I figured someone would find it interesting or useful.

Sometimes I can be a bit OCD about the files on my computer.  Everything has a certain place, and every folder has a meaning.  The same holds true for the music files I’m working on.  When I’m nearly finished with a song, I start exporting .wav files and encoding them to various formats, including mp3 for the downloads, Ogg Vorbis for the streaming, and FLAC for my own archives.  On my file server here at home is a special folder I keep all these in called Recorded Files.  In here are four other folders, one for each type, named new waves, new mp3s, new flacs, and new oggs.  The idea is that I drop new .wav files that are candidates for release into the new waves folder, then place the other formats created from it in their respected folder.  It’s a bit convoluted, but I do have a reason for doing it this way.  In the past I would have trouble keeping track of which wave was the latest file, and knowing if the mp3 I had was from that latest wave file or not.  Now I know some of you would say, “well, why don’t you just add dates to the file names?”  I could, but when I first started working with this layout I didn’t have a lot of extra space to work with to keep multiple versions.  Plus, I already “versioned” my source files in Sonar, so I can always go back in time with those instead.  So it just made sense to do it this way instead.

Anyway, I do all my mp3, FLAC, and Ogg Vorbis encoding directly on my server, which runs Linux, since it’s a bit faster than my desktop and all the tools are there in one location.  Well one day I realized that I could write a simple shell script to automate creating all these different files from the original .wav files rather than doing it by hand.  Doing this would also further help prevent a situation where I’m left going, “Is this mp3 from the latest .wav file? Is the .wav file even the latest one?  Grr, I’m going to have to re-export and re-edit.”

So I wrote a script one day to do just that.  For a long time the script worked, but it wasn’t that robust.  While it did know how to recreate only the files missing from the new mp3s, new flacs, and new oggs folders, it didn’t know how to overwrite specific files.  Plus, it didn’t really handle command line arguments very well, and it didn’t handle any metadata.  So, I decided to rewrite it in Python and make it better.

The new script can look for .wav files to encode in any arbitrary directory, and can also output each format in any arbitrary directory.  It also knows how to insert some default metadata tags into each file it encodes (the defaults can be changed in the script), figure out the title and track number (if it exists) from the file name, and how to work on individual files.

So there you have it.  A small bit of insight into how I handle my music.  It may not seem like much, but having this script actually saves me a lot of time and headaches.  If you want, you can download a copy of the script here (right-click and Save As).  To run, you need Python (2.6 and newer, though an older version might work); command line tools for lame, flac, and oggenc; and id3v2.