Greg's Tech blog

Podcast Converter

Wednesday 29 of November, 2006

I found a new Podcast called the Story of Digital Identity SToDID. No sooner did I discover it, then the host, Aldo Castañeda, switched to m4a format. He did so due to potential licensing and file size issues with mp3. See his comments in the comments for Episode #38 (cache) where we diascussed the issue.

Well, I own a Creative Zen Nomad Xtra and use it regularly to listen to podcasts. It does not support the m4a format. I went looking for a way to access the content, found a couple tools and wound up writing this Windows script to convert the file from m4a to mp3. It uses some open source tools — faad, lame and tag to do the heavy lifting. One caution - it removes the original .m4a file when complete. Instructions to stop that are included.

As an after thought, I added the ability to rip the audio m4v files as well.

I use Juice to download my podcasts and it provides a feature to run a command after each download. It provides two parameters for use with the command.
%f = filename
%n - podcast name

I use this command in juice:

start "postDL" cmd /c c:\acc\m4tomp3.cmd "%f" "%n"

The script access %f as %1 and %n as %2

@echo off
::Greg Martin  11/29/06
::Converts m4a and m4v files to mp3 for use on a mp3 player
::  (note: if you've not seen them before, a double colon is similar to a comment (REM)

::sleep to give juice time to complete file write
sleep 5

set podname=%2
set origFileName=%1

:: since a specific filename is passed as %1 the 'for' does nothing except parse
:: the extension & filename
:: fext is set to file extension (.m4a  or mp3)
:: fname is set to filename (less extension)
for %%a in (%1) do set fext=%%~xa& set fname=%%~na& set fpath=%%~dpa

::Convert if needed
if %fext%==.m4a call :convertit %1
if %fext%==.m4v call :convertit %1
call :settag
goto :eof

@echo export to wav
::use faad to decode to wav
faad %1
sleep 1
@echo convert to mp3
::use lame to encode to mp3
lame -h -b 96 "%fpath%%fname%.wav" "%fpath%%fname%.mp3"
:: cleanup (remove %origFileName% from the net line to keep the original file after conversion)
del %origFileName% "%fpath%%fname%.wav"
goto :eof

tag --removeid3v2 --genre 90 --album %podname% --title "%fname%" "%fpath%%fname%.mp3"
goto :eof

Feel free to use this script. Please share any changes with me to help make it better.