mutoo
2/7/2017 - 5:49 AM

wav2mp3

wav2mp3

#!/bin/bash
process() {

	dir=$@
	echo "processing $dir/"
	
	FILES=$@/*
	IFS=$(echo -en "\n\b")
	for file in $FILES; do
		if [ -f "$file" ]; then
			# echo "found file $file"

			if [[ $file == *.wav ]]; then
				dir=$(dirname "$file")
				fileWithoutExt=$(basename "$file" .wav)
				mp3file="$dir/$fileWithoutExt.mp3"
		
				if [ -f "$mp3file" ]; then
					echo "$mp3file already exist"
				else
					echo "converting $file..."
					lame "$file"
				fi
			
				if [ force ]; then
					rm -f "$file"
					echo "removed $file"
				else
					rm -i "$file"
				fi
			fi	

		elif [ -d $file ]; then
			# echo "found directory $file"
			process $file

		fi
	done
}

while getopts "f" arg; do
  case $arg in
    f)
      force=true
      ;;
  esac
done

process $(pwd)