tagging mp3s

Final installment of the podcast bash script for a while. I will eventually add the ability to auto-sync with my iPod, but I'm still undecided at which command line iPod tools I want to use. Currently gtkpod is doing a great job of keeping my iPod fed, and it's simple to load it up, add my podcast folder and sync. gtkpod weeds out the dupes and automatically transfers just what's needed.

I'm just going to describe the tagmp3 function, much like I did for the updated getmp3 function last time. Read the script to see how I hook the tagmp3 function into getmp3. It could all us a bit more error handling, but it works well enough now to be useful.

I am using id3v2 from here. It is easy to compile and only has one dependency, id3lib. I'm using the id3lib and id3lib-devel RPMs for FC3 from FreshRPMs.

function tagmp3() { fname="${@}"

A new trick I learned recently. $@ references all the arguments on the command line.

if [ ! -f "${fname}" ] ; then echo "Error, file not found: ${fname}" else

I'm setting the tag variables here. A little farther down we will unset them if the tag is set in the mp3. I've keept the code formated like it is to make commenting out or in each tag type easy. One feature I'd like is to change feeds.lst to xml and use that to dictate album and/or genre for each feed.

# Set all the tags # tit2="${TITLE}" talb="${CHANNEL}" year=$(date --date="${DATE}" +%Y) if [[ "${year}" = "" ]] ; then year=$(date %Y) ; fi tyer="${year}" tcon="podCast"

read the existing id3 tags. As mentioned above, when we see a tag being used, unset it's var so we don't overwrite it.

# If the id3tag is already used in the file, unset the variable # This way we won't set the id3tag when the author has set one already. while read line ; do first=$(echo "${line}"|awk {'print $1'}) case "${first}" in 'TIT2') tit2="" ;; # comment this lines out to force overwriting the tag. 'TALB') talb="" ;; # comment this lines out to force overwriting the tag. 'TYER') tyer="" ;; # comment this lines out to force overwriting the tag. # 'tcon') tcon="" ;; # Uncomment to keep existing genre. esac done < <(id3v2 -l "${fname}")

Setting tags. There is certainly a more efficient way to do this, but for now I'll keep it easy to comment each tag. We could do this a bit more elegantly with more config options and better parsing of the published id3tags.

# for the tags that are set, tag the file. if [[ "${tit2}" != "" ]] ; then echo Setting title ; id3v2 --TIT2="${tit2}" "${fname}" ; fi if [[ "${talb}" != "" ]] ; then echo Setting album ; id3v2 --TALB="${talb}" "${fname}" ; fi if [[ "${tyer}" != "" ]] ; then echo Setting year ; id3v2 --TYER="${tyer}" "${fname}" ; fi if [[ "${tcon}" != "" ]] ; then echo Setting genre ; id3v2 --TCON="${tcon}" "${fname}" ; fi fi }

podcast.007.sh

I will package up the final script, complete with a sample feeds file for download, and start a projects page here for it at a later date.

If I failed to explain anything well enough, please comment, or drop me an email at anton at lr2 dot com.

Leave a Reply

Your email address will not be published. Required fields are marked *