#!/bin/bash
#
# Modify to suit
CONFIGDIR='/volume1/@appstore/tvheadend-testing/var'
RECORDINGS='/volume1/TV/'

echo "Scanning logs and recordings"

COUNT=0

for FILE in $(find $RECORDINGS -type f -name "*.ts" -o -name "*.mkv") ; do
    LOGFILE=$(grep ${FILE} $CONFIGDIR/dvr/log/* | cut -d ':' -f 1)
    LOGFILE=${LOGFILE//@/\\@}
    if [ "$LOGFILE" ]
    then
      echo "Preparing to import $(basename ${FILE}) with log $(basename ${LOGFILE})"
      #tvhimport.sh "${FILE}" -l $LOGFILE
    else
      echo "Preparing to import $(basename ${FILE}) with no log"
      #tvhimport.sh $COMMAND "${FILE}"
    fi
    let COUNT++
    if [ $COUNT -gt 5 ]; then
      exit 0
    fi
done
