#!/bin/bash
#
# $Id: tv_grab_nl_upc_wrapper,v 1.8 2008/04/21 13:56:18 ianmacd Exp $
#
# Wrapper script for tv_grab_nl_upc.

# Uncomment this next line to get MythTV 0.21 mythfilldatabase to produce
# useful debugging info as per MythTV < 0.21.
#
# mfdb_debug="-v important,general,xmltv"

# Create a temp file for the XML.
#
xml_file=$( mktemp -p ~/.xmltv upc.XXXXXXXXXX )

# Make sure the temp file doesn't get left behind.
#
trap "rm $xml_file; exit 1" SIGINT SIGQUIT SIGTERM

# Adjust the video source as needed.
#
video_source=2

# Video source can also be provided on the command line.
#
if [ "$1" = --video-source ]; then
  video_source=$2
  shift
  shift
fi

# Get the programme data.
#
LANG=nl_NL /usr/local/bin/tv_grab_nl_upc $* > $xml_file

# Feed it to MythTV.
#
# Use this line for MythTV < 0.21:
#
# [ $? -eq 0 ] && mythfilldatabase --no-delete --file $video_source -1 $xml_file
#
# and this line for MythTV 0.21:
#
[ $? -eq 0 ] && mythfilldatabase $mfdb_debug --file $video_source $xml_file

# Delete temp file.
#
rm $xml_file 2>/dev/null
