EPGStreamUpdateTvGuide

From MythTV Official Wiki
Jump to: navigation, search

I wrote a script to download the xmltv to a temporary file, then upload it to the database using the mythfilldatabase --file option. This could probably be turned into a standard xmltv tv_grab_au script quite easily. I created it because the new oztivo grabbers need a version of the perl xmltv libraries not available in Ubuntu Dapper.

#!/bin/bash

CLIENT_ID=""
POSTCODE=""
CONFIGFILE="/etc/mythtv/mysql.txt"

if [ -z "$CLIENT_ID" ]
then
        echo "Please update this script ($0) and set CLIENT_ID at the top"
        echo "If you haven't already, then go to http://epgstream.net/ and register"
        exit 1
elif [ -z "$POSTCODE" ]
then
        echo "Please update this script ($0) and set POSTCODE at the top"
        exit 1
elif [ ! -x "$(which curl)" ]
then
        echo "Please install curl (or modify this script to use wget or something)"
        exit 1
fi

# create a safe temporary file to store the xml data
temp_file=`/bin/tempfile -s .xml`

echo "Downloading new data..."
curl -sS "http://free-epg.epgstream.net/xmltv/xmltvService.aspx?clientId=$CLIENT_ID&guideType=free&clientType=MythTV&countryCode=au&geographicId=$POSTCODE&medium=digital.tv" | gunzip > $temp_file

echo "Checking source id..."

# find the sourceid by interrogating the database
mythtv_username=`grep DBUserName $CONFIGFILE|cut -d'=' -f2`
mythtv_password=`grep DBPassword $CONFIGFILE|cut -d'=' -f2`
mythtv_databasename=`grep DBName $CONFIGFILE|cut -d'=' -f2`
source_id=`mysql -u$mythtv_username -p$mythtv_password --safe-updates --select_limit=1 --skip-column-names $mythtv_databasename -e "select sourceid from cardinput;"`

echo "Importing data into database..."

# check if using old version of mythfilldatabase
if (mythfilldatabase --help|grep -q -- '--file <sourceid> <offset> <xmlfile>')
then
        mythfilldatabase --file $source_id -1 $temp_file
else
        mythfilldatabase --file $source_id $temp_file
fi

rm $temp_file