#!/bin/sh
#
# Check that there is an album cover in every album directory

base_dir=$HOME/Music

if [ $1 ]; then
  music_dir=$1
else
  echo ""
  echo "Please specify a music directory inside ${base_dir}"
  echo ""
  exit 1
fi

tmpy=/tmp/check_music_covers

# Create a tmp directory for dumps
if [ ! -d "${tmpy}" ]; then
  mkdir ${tmpy}
fi

# Scan through all of the directories
for this_music_dir in ${music_dir}
do
  # Scan for artists
  echo "Scanning ${this_music_dir} directory ..."
  ls -1 "${base_dir}/${this_music_dir}" > ${tmpy}/${this_music_dir}

  # Scan for albums
  while read artist
  do
    ls -1 "${base_dir}/${this_music_dir}/${artist}" > ${tmpy}/${this_music_dir}-${artist}
    while read album
    do
      if [ -f "${base_dir}/${this_music_dir}/${artist}/${album}/folder.jpg" ]; then
        if [ "$2" = "-v" ]; then
          echo "  ${artist} - ${album} - \"folder.jpg\" found"
        fi
      else
        echo "  ${artist} - ${album} - \"folder.jpg\" NOT FOUND"
      fi
    done <${tmpy}/${this_music_dir}-${artist}
  done <${tmpy}/${this_music_dir}
done
  
# Now clean up the tmp area
""rm -f -R ${tmpy}
