#!/bin/sh
#
# sebastien.martini@gmail.com - 06/24/2006
# license: do what you want, but don't sue me in anycase :)
#

# FILL THESE VARIABLES:
#
# please append trailing '/' to dirnames
#
# source directory:
ITUNES_DIR="/my-itunes-dir/"
# destination directory:
DST_DIR="/my-dst-dir/"
# log file:
LOG="/tmp/trace.txt"


# cleanout log file
echo -n "" > $LOG


# copy all the titles from:
#   /src/artist-x/album-x/
# to:
#   /dst/album-x/
for artist in $ITUNES_DIR*
  do
  if [ -d "$artist" ]
      then
      echo "for artist: $artist" >> $LOG
      for album in "$artist"/*
	do
	if [ -d "$album" ]
	    then
	    echo "$tab for album: $album" >> $LOG
	    basename=${album##/*/}
	    if [ ! -d "$DST_DIR$basename" ]
		then
		echo "$tab $tab create dst dir: $DST_DIR$basename" >> $LOG
		mkdir "$DST_DIR$basename"
	    fi
	    cp -f "$album"/* "$DST_DIR$basename"
	fi
      done
  fi
done


# check that the numbers of copied titles match between the src and dst dirs.
echo "" >> $LOG
dirs=("$ITUNES_DIR" "$DST_DIR")
for rep in "${dirs[@]}"
  do
  echo -n "${rep}:" >> $LOG
  find "${rep}"  -name '*.mp3' -or -name '*.aac' -or -name '*.ogg' -or -name '*.wma'  | wc -l >> $LOG
done

