#!/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
    if [ -f "$FILE" ]; then
      LOGFILE=$(grep ${FILE} $CONFIGDIR/dvr/log/* | cut -d ':' -f 1)
      if [ "$LOGFILE" ]
      then
        echo "Preparing to import ${FILE} with log ${LOGFILE}"
        #tvhimport.sh "${FILE}" -l $LOGFILE
      else
        echo "Preparing to import ${FILE} with no log"
        #tvhimport.sh $COMMAND "${FILE}"
      fi
      let COUNT++
      if [ $COUNT -gt 5 ]; then
        exit 0
      fi
    fi
done
