 /bin/bash
# made by Erik Bergh
# erik.bergh@hiof.no
# msn@gakkgakk.org
# Useage: ./convert.sh destination


# allowed extentions
extentions=(mp3 MP3)

# paths 
Destination=$1

# browsing music dir

for file in $Source*
  do
  # if not a directory
  if [ ! -d "$file" ] ; then
      ext=${file##*.}
      # checking if a file has a valid extention
      for i in ${extentions[@]}; do
	  if [ "$ext" = "${i}" ]; then
              # getting artist name
	      newfile=`echo $file | tr -t ' ' '_'`;
	      echo $file;
	      echo $newfile;
	      mv "$file" "$newfile";
	      Title=`exiftool -Title $newfile | perl -ne '/: (.*)/; print $1'`
	      Artist=`exiftool -Artist $newfile | perl -ne '/: (.*)/; print $1'`
	      Album=`exiftool -Album $newfile | perl -ne '/: (.*)/; print $1'`
	      lame -b64 --add-id3v2 --ta '$Artist' --tl '$Album' --tt '$Title' "$newfile" "$Destination/$newfile";
   
	 fi
      done
  fi
done