TVHeadend stuff

From Combobulate

TVHeadend

Recently ditched Myth for TVHeadend.

Script to shut the bloomin' thing down after recording:

#!/bin/sh

export PATH=/home/tvh/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

if [ "`curl -s http://script:script@localhost:9981/api/status/connections | tr } '\n' | grep peer | grep -v 127.0.0.1`" != "" ]; then
        echo "Not shutting down due to active connections" | logger
        exit 0
fi
curl -s http://script:script@localhost:9981/api/dvr/entry/grid_upcoming | grep -q '"sched_status":"recording",'
match=$?
if [ "$match" != "0" ]; then
#       echo not recording.
        next_recording=`curl -s http://script:script@localhost:9981/api/dvr/entry/grid_upcoming | sed "s/.*start_real.:\([0-9]*\).*/\1/"`
        gap=$(($next_recording-`date +%s`))
        echo Next recording: `date -d "1970-01-01 $next_recording sec" "+%F %H:%M:%S" -u` | logger
        if [ $gap -gt 900 ]; then
                wakeup=$((next_recording-600))
                wakeup_date=`date -d "1970-01-01 $wakeup sec" "+%F %H:%M:%S"`
                echo "Waking up at: $wakeup_date" | logger
                /usr/bin/sudo /usr/sbin/rtcwake -m no -t $wakeup
                /usr/bin/sudo /sbin/shutdown -P now
        fi

else
#       echo recording...
        echo "Still recording. Not shutting down." | logger
fi