#!/bin/sh
# Copyright (C) 2009 - 2012 vortexbox.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# Changelog:
#
# Fri May 20 2011 Ron Olsen <ronolsen@comcast.net>
# * Use <input-dir> and <output-dir> arguments to flac2m4a.sh


function echolog {
echo "`date +'%m/%d/%Y %H:%M:%S'` - $1"
}

/opt/vortexbox/getcoverart

if [ -f /etc/vortexbox/automp3 ]; then
  echo "" >> /var/log/mirror.log
  echolog "Starting auto mp3 mirror." >> /var/log/mirror.log
  echo "" >> /var/log/mirror.log
  if [ -f /etc/vortexbox/mirror-flac-mp3.running ]; then
	echo "" >> /var/log/mirror.log
	echolog "mp3 mirroring allready in progress." >> /var/log/mirror.log
	echo "" >> /var/log/mirror.log
	if [ ! -f /etc/vortexbox/mirror-flac-mp3.again ]; then
		touch /etc/vortexbox/mirror-flac-mp3.again
		/opt/vortexbox/run-again mirror-flac-mp3.again &
	fi
  else
	echo "" >> /var/log/mirror.log
	echolog "Mirroring FLACs to mp3." >> /var/log/mirror.log
	echo "" >> /var/log/mirror.log
	/usr/local/sbin/mirror-flac-mp3 >> /var/log/mirror.log &
  fi
fi

if [ -f /etc/vortexbox/autoaac ]; then
  echo "" >> /var/log/mirror.log
  echolog "Starting auto AAC mirror." >> /var/log/mirror.log
  echo "" >> /var/log/mirror.log
  if [ -f /etc/vortexbox/mirror-flac-aac.running ]; then
	echo "" >> /var/log/mirror.log
	echolog "AAC mirroring allready in progress." >> /var/log/mirror.log
	echo "" >> /var/log/mirror.log
	if [ ! -f /etc/vortexbox/mirror-flac-aac.again ]; then
		touch /etc/vortexbox/mirror-flac-aac.again
		/opt/vortexbox/run-again mirror-flac-aac.again &
	fi
  else
	echo "" >> /var/log/mirror.log
	echolog "Mirroring FLACs to AAC." >> /var/log/mirror.log
	echo "" >> /var/log/mirror.log
	/usr/local/sbin/flac2m4a.sh /storage/music/flac /storage/music/m4a >> /var/log/mirror.log &
  fi
fi	



