Project

General

Profile

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

Hiro Protagonist, 2020-05-12 06:32

 
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
        if [ $? -eq 0 ] ; then
34
          echo "Sending create command for \"$FILENAME\""
35
          if curl -q --data @"$JSONFILE" "http://$USER:$PASS@localhost:9981/api/dvr/entry/create" ; then
36
            echo "Imported \"$FILENAME\" successfully"
37
          fi
38
          echo
39
        else
40
          echo "Failed to import $(basename ${FILE}) - unable to access log"
41
          ls -lahF $CONFIGDIR/dvr/log/
42
          exit 0
43
        fi
44
      else
45
        echo "Failed to import $(basename ${FILE}) - no log"
46
        #tvhimport.sh $COMMAND "${FILE}"
47
        ls -lahF $CONFIGDIR/dvr/log/
48
        exit 0
49
      fi
50
#      let COUNT++
51
#      if [ $COUNT -gt 5 ]; then
52
#        exit 0
53
#      fi
54
    fi
55
    sleep 5
56
done
    (1-1/1)