--- /dev/null
+#!/bin/bash
+
+# The sourceid value for your FreeviewHD source.
+SOURCEID=1
+
+# Adapter number of DVB-T card.
+ADAPTER=0
+
+# DVB-T multiplex frequency (kHz)
+DVB_T_FREQ=610000
+
+# Number of times to try mhegepgsnoop.py if it fails.
+TRIES=5
+
+# Amount of time to sleep between tries.
+SLEEP_TIME=5m
+
+# Output file to store the xmltv EPG data.
+TEMP_FILE=/tmp/xmltv.xml
+OUTPUT_FILE=/home/mythtv/.mythtv/freeview.xml
+
+# Channel map file.
+#MAP_FILE=/home/mythtv/.mythtv/mhegepgsnoop_channel_map.txt
+
+# Force a specific location for finding the MythTV configuration. If you get error
+# messages such as:
+# Error accessing mythconverg database with Python bindings
+# then uncomment the next line below and adjust it to point to a directory containing
+# a valid config.xml for access to your backend. It needs to be readable by the user
+# that is running this script. There is usually one in:
+# /etc/mythtv
+# /home/<your mythfrontend user>/.mythtv
+# /home/mythtv/.mythtv
+#MYTHCONFDIR=/etc/mythtv
+
+retval=0
+
+if [ -e "$TEMP_FILE" ] && [ -f "$TEMP_FILE" ] ; then
+ rm "$TEMP_FILE"
+fi
+
+for ((i=1; i<=$TRIES; i++)); do
+ # Get the MHEG5 EPG data from the DVT-T multiplex.
+ echo "Try $i, running mhegepgsnoop.py now"
+ #mhegepgsnoop.py -v -zp -b -t 5 -d /dev/dvb/adapter${ADAPTER}/demux0 -o $TEMP_FILE -f $MAP_FILE
+ mhegepgsnoop.py -v -zp -b -t 5 -d /dev/dvb/adapter${ADAPTER}/demux0 -o $TEMP_FILE
+ retval=$?
+ if [ $retval -eq 0 ]; then
+ break
+ fi
+ rm $TEMP_FILE
+ echo "Warning: mhegepgsnoop failed (retval=$retval), retrying after sleep $SLEEP_TIME"
+ sleep $SLEEP_TIME
+done
+
+if [ $retval -ne 0 ]; then
+ echo "Error: mhegepgsnoop failed after $TRIES tries (retval=$retval)!"
+else
+
+ mv $TEMP_FILE $OUTPUT_FILE
+
+ # The MHEG5 data is raw and has not been processed by xmltv-proc-nz.
+ # So do that now.
+ echo "Running xmltv-proc-nz on the MHEG5 data"
+ cat $OUTPUT_FILE | /usr/local/bin/xmltv-proc-nz --verbose >$TEMP_FILE
+ RET_CODE=$?
+ if [ $RET_CODE -ne 0 ]; then
+ echo "****** xmltv-proc-nz on MHEG5 Freeview data failed, using raw data ******"
+ else
+ mv $TEMP_FILE $OUTPUT_FILE
+ fi
+
+ chmod a+rw $OUTPUT_FILE
+ mythfilldatabase --only-update-guide --sourceid $SOURCEID --file --xmlfile $OUTPUT_FILE
+fi
+
+exit $retval