Project

General

Profile

RE: Re-Import Existing Recordings ยป importall.sh

Hiro Protagonist, 2020-05-12 05:45

 
1
#!/bin/bash
2
#
3
# Modify to suit
4
CONFIGDIR='shortcut'
5
RECORDINGS='/volume1/TV/'
6
JSONFILE="/tmp/import.json"
7
USER=admin
8
PASS=secret
9

    
10
echo "Scanning logs and recordings"
11

    
12
COUNT=0
13

    
14
for FILE in $(find $RECORDINGS -type f -name "*.ts" -o -name "*.mkv") ; do
15
    FILENAME=$(basename $FILE)
16
    FTYPE=""
17
    NAME=${FILENAME%.ts}
18
    if [ "$FILENAME" = "$NAME" ]; then
19
      NAME=${FILENAME%.mkv}
20
      if [ "$FILENAME" != "$NAME" ]; then
21
        FTYPE=mkv
22
      fi
23
    else
24
      FTYPE=ts
25
    fi
26
    if [ "$FTYPE" = "ts" ] || [ "$FTYPE" = "mkv" ]; then
27
      LOGFILE=$(grep ${FILE} $CONFIGDIR/dvr/log/* | cut -d ':' -f 1)
28
      if [ "$LOGFILE" ]
29
      then
30
        echo "Preparing to import $(basename ${FILE}) with log $(basename ${LOGFILE})"
31
        echo -n "conf=" > "$JSONFILE"
32
        cat "$LOGFILE" >> "$JSONFILE"
33
        echo "Sending create command for \"$FILENAME\""
34
        if curl -q --data @"$JSONFILE" "http://$USER:$PASS@localhost:9981/api/dvr/entry/create" ; then
35
          echo "Imported \"$FILENAME\" successfully"
36
        fi
37
        echo
38
      else
39
        echo "Failed to import $(basename ${FILE}) - no log"
40
        #tvhimport.sh $COMMAND "${FILE}"
41
        ls -lahF $CONFIGDIR/dvr/log/
42
        exit 0
43
      fi
44
#      let COUNT++
45
#      if [ $COUNT -gt 5 ]; then
46
#        exit 0
47
#      fi
48
    fi
49
    sleep 5
50
done
    (1-1/1)