#!/bin/sh
# goepg 1.1 2004.10.30 by tCC
# goepg 1.2 2004.10.31 changed by mirakels
#        - add -p to mkdir
#        - introduce a few vars to simplify configuration of script
#        - keep current stream info in var (e.g. no need for tmp file)
#        - only switch stream if needed
# goepg 1.3 2004.11.22 changed by mirakels
#        - determine time offset from current date
# goepg 1.4a 2005.02.23
#        - Changed by Redneck Eyeball to work with EPGdb 2.0
# goepg 1.4b 2005.04.19 -  mirakels
#        - use dreambox status instead of streaminfo to get current stream
#          (this is no problem now since httpauth is assumed active)
# goepg 1.5 2005.06.30 - mirakels
#        - adapt to the streaminfo changes in enigma: uses xml know.
# getepg 1.6 2005.07.03
#        - Changed by Redneck Eyeball to work with EPGdb 2.2

#
# Use Nederland 1 for EPG data
#
EPGCHAN="1:0:1:fab:451:35:c00000:0:0:0:"

#
# Getting the current stream information
#
CURRCHAN=`wget -O - -q http://root:dreambox@127.0.0.1/xml/streaminfo | grep "<reference>" | sed s'/.*>\(.*\)<.*/\1/'`

#
# Switching to EPG channel
#
[ "$CURRCHAN" != "$EPGCHAN" ] && wget -O /tmp/goepg.tmp -q "http://root:dreambox@127.0.0.1/cgi-bin/zapTo?path=$EPGCHAN"

#
# Updating EPG information
#
/var/tuxbox/plugins/mhwepg2 -l > `grep -e '/epgui.dat' /var/tuxbox/config/epgui.conf | cut -c 13-40`

#
# zapping back
#
[ "$CURRCHAN" != "$EPGCHAN" ] && wget -O /tmp/goepg.tmp -q http://root:dreambox@127.0.0.1/cgi-bin/zapTo?path=$CURRCHAN

#
# Removing temporary files
#
rm /tmp/goepg.*

exit 0

#
# The End
#
