Project

General

Profile

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

Hiro Protagonist, 2020-05-11 04:55

 
1
#!/bin/bash
2
#
3
# Modify to suit
4
CONFIGDIR='/volume1/@appstore/tvheadend-testing/var'
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 "Preparing to import $(basename ${FILE}) with no log"
40
        #tvhimport.sh $COMMAND "${FILE}"
41
      fi
42
#      let COUNT++
43
#      if [ $COUNT -gt 5 ]; then
44
#        exit 0
45
#      fi
46
    fi
47
done
    (1-1/1)