Bible in MP3 Smartlist

June 2, 2007

I recently bought the NIV Bible on MP3 (via Amazon.com).

The Bible offers an interesting problem of scale. There are 66 books spread over 1,189 tracks taking up about 3GB of disk space. The books are not alphabetized. Each book has its own chapter 1. Add to it that the book count resets for the New Testament.

I am working my way through the Bible in 90 days, from Genesis to Revelation. I want to create a partial playlist of unplayed chapters in order.

My first thought was to assign track numbers. Unfortunately you can’t set a track number higher than 255, which is 934 less than what I needed.

So I looked at the filenames. Fortunately the files are named in a predictable pattern. For example:

03lev12.mp3

Working right to left, we start with “12” which is the chapter. “lev” stands for “Leviticus” with is the third (03) book in the Bible.

If 1,189 tracks tells you anything, it screams “Script Me!” and if you are scripting MP3s, you need id3tool which I got from MacPorts by going to the right folder and issuing a “sudo port install id3tool” and then scripted out a loop for all the Old Testament MP3s like this:

for i in *mp3
do

CHAPTER=id3tool $i | egrep "^Song Title:" |awk '{print $NF}'

BOOK=echo $i | cut -c 1-2

id3tool —set-title=”Book $BOOK Chapter $CHAPTER” \
—set-artist=”NIV Bible” \
—set-note=”Bible Old Testament” $i

done

What that says, in English, is “For each MP3 that you find in this directory, run id3tool on the file, grab the line for Song Title, and take the last part of it (originally it said something like Chapter 1). Second, take the filename and cut off the first two characters (this gets us the number of the book, such as 01 for Genesis.) Finally, run id3tool again, set the title to have both the Book number and the Chapter Number (so chapter 10 in Genesis is Book 01 Chapter 10), then set the Artist to NIV Bible (it was originally Zondervan, which is a publishing company, not an Artist). It also added a note as well.”

I’m not sure what I’ll use the note for, but it seemed like a good idea to have “Bible” so I could search for that, and “Old Testament” so I could search for that too.

The trick, then, becomes what to do with the New Testament section. The filenames start over again at 01 for Matthew (i.e. 01matt15.mp3 is the 15th chapter of Matthew, the first book of New Testament) but I didn’t want to have chapters from Matthew and Genesis mixed in together.

I put all the New Testament MP3s in a different folder before I ran the previous loop. Then I ran a very similar loop on the New Testament files except that after we get the $BOOK variable which gives us the number, I added 39 to it, because there are 39 books in the Old Testament. So if Matthew is book 1 in the New Testament (and it is) it is the 40th book in the Bible. Voilà.

for i in *mp3
do
  CHAPTER=id3tool $i | egrep "^Song Title:"|awk '{print $NF}'

BOOK=echo $i | cut -c 1-2

BOOK=expr $BOOK + 39

id3tool —set-title=”Book $BOOK Chapter $CHAPTER” \
—set-artist=”NIV Bible” \
—set-note=”Bible New Testament” $i

done

Now this is the Smart Playlist that I can use:

Bible-Smart-Playlist-655x282.png

Which says, get 900MB of tracks where the Artist is “NIV Bible” and the Play Count is 0, which fits nicely onto my 1GB iPod shuffle.

I’m not sure if anyone else will ever use this. Not only does it require you to install a new program, it’s all command-line. If someone can tell me how to do this in AppleScript, well, all the better.

Previous post:

Next post: