Thursday, December 23, 2004

Shell script to convert aiff file to mp3 and add id3 tags using lame and id3tool

I am working on a shell script to help Michael Geoghegan of Reel Reviews podcast fame in his podcast production. I though I would post this as it may be of use to other podcasters. It is setup for OSX but should work on any *nix OS with minor changes. Windows version is possible but would probably have to be a vbscript or batch file or something of that order.

1. it converts any aiff file dropped into a folder to a 64kbps mono mp3 file (scanned every 10 seconds)
2. Adds some of the id3 tags:
- name: Reel-(the date)
-author: Michael Geoghegan
- album: Reel Reviews
-Comments (note):
-Year (the current year)
3. Moves the aiff files to an aiff subfolder
4. Moves the processed mp3 file to a mp3s subfolder

Here is the script source:

#! /bin/bash
while ((1));
for aifffile in *.aiff;
base=`basename $aifffile .aiff`
my_date=`date "+%m-%d-%Y"`
my_year=`date "+%Y"`

lame -h -m m -b 64 $base.aiff $base.mp3
id3tool $base.mp3 -r "Michael Geoghegan" -y $my_year -t "Reel-$my_date" -a "Reel Reviews" -n "$my_note1"
mv $base.aiff aiffs
mv $base.mp3 mp3s
sleep 10;

There is a bit of setup to do. Setup assumes OSX 10.3, lame and id3tool are installed. I had to compile lame and id3tool. Suposedly you can install them with fink in OSX but I couldn't get it to work so I just downloaded the source for these 2 and did it myself.

so to use the script
-install lame and id3tool.
-create a bin folder in your home directory /Users/your-user-name/bin
-create subfolders in bin called aiffs and mp3s
-copy the attached file (podcast.bsh) to the bin folder
-change the permissions of the podcast.bsh so it can execute.
-To do this open the terminal in /Applications/Utilities/Terminal.
- Type cd bin (return)
- Then type chmod 755 podcast.bsh
- Last type ./podcast.bsh (you have to keep the terminal application and window open (but you can minimize it to the dock)

Now any aiff file dropped in the bin folder is converted, id3 tags added and moved to the mp3s subfolder.

Here is what is left to make it really work well.

1. Testing. I just tested this on one very short system beep aiff file. Need to make sure it works with bigger files - it should but need to be tested
2. Prompt you for the name of the film. The script already just grabs the date from the computer. This part may need to be done in applescript - which is ok for OSX bu how could this be done to make it portable to other OSes?
3. Do the artwork thing. How do you do this? Drag the photo file into the iTunes artwork window? Does the artwork thing work with other media apps besides iTunes?
4. The id3tool seem to only allow a short snippet of text in the comment (note) tag, I wasn't able to put in the line breaks either.
5. Seems to me it would be useful to have it automatically ftp the mp3 wherever it needs to go no?

Listen to this article Listen to this article


At 3:25 PM, Blogger thecolor said...

Thanks for the great post.

This has enabled me to post my text blogs in audio as well so much easier.

Now if I could figure out the script enough to add an auto function for the say command as well, I'd be able to auto post in text and audio instantly. :)


TheColor Cypher


Post a Comment

<< Home