#!/bin/bash

DELETE_ORIGINAL=true

# do some parameter checking
if [ -z "$1" ]
then
	echo "usage:   `basename $0` path_to_mp3_file"
	exit 1
fi

ORIGINAL_FILENAME=$1
NEW_FILENAME=${ORIGINAL_FILENAME%.*}.ogg

# convert the file
sox $ORIGINAL_FILENAME $NEW_FILENAME

# convert the id3 info to ogg comments
ARTIST=`mp3info -p "%a" $ORIGINAL_FILENAME`
TITLE=`mp3info -p "%t" $ORIGINAL_FILENAME`
GENRE=`mp3info -p "%g" $ORIGINAL_FILENAME`
vorbiscomment -a -t "ARTIST=$ARTIST" -t "TITLE=$TITLE" -t "GENRE=$GENRE" $NEW_FILENAME

# remove the original file
if $DELETE_ORIGINAL
then
	rm $ORIGINAL_FILENAME
fi
