#!/bin/sh
#
#  Ogg3mp
# Usage : oggtomp3 file.ogg
#
#
#

WMAFILE=$1
WAVFILE=${WMAFILE%ogg}wav
MP3FILE=${WMAFILE%ogg}mp3


test_for_mplayer() {
	which mplayer >/dev/null 2>&1
	if [ "$?" = "1" ]; then
		echo -e "\033[1;31mWarning:\033[0m  Mplayer not found"
		exit 1
	else
		echo -e "\033[1mInfo:\033[0m  Mplayer found"
	fi
}

test_for_lame() {
	which lame >/dev/null 2>&1
	if [ "$?" = "1" ]; then
		echo -e "\033[1;31mWarning:\033[0m  lame not found"
		exit 1
	else
		echo -e "\033[1mInfo:\033[0m  Lame found"
	fi
}


if [ ! "$WMAFILE" ] ; then
	echo -e "\n \033[1m     Oggtomp3\033[0m \n "
	echo -e "      Usage: oggtomp3 oggfile.ogg \n "
	echo -e "      needs mplayer and lame to work \n"
	exit 1
else
		test_for_mplayer
		test_for_lame
		mplayer -ao pcm:file="$WAVFILE" "$WMAFILE"
		lame -m m -b 24 -s 22.05 "$WAVFILE" "$MP3FILE"
		rm -f "$WAVFILE"
fi

unset WMAFILE
unset WAVFILE
unset MP3FILE
exit 0