#!/bin/bash
# Script for setting the xmltv ids in MythTV
# - Scan for DVB channels in mythtv-setup
# - Edit xmltv.dat with your channel data
# - Run this script

#--------------------------------------------------------------------------
setchan_rt()
{
  gawk -F "," '
    {
      printf("update channel set xmltvid=\"%s\",icon=\"%s\" where callsign=\"%s\";\n", $2,$4,$1);
    }
  ' xmltv.dat
}

#--------------------------------------------------------------------------
setchan_dvb()
{
  gawk -F "," '
    {
      printf("update channel set xmltvid=\"%s\",icon=\"%s\" where callsign=\"%s\";\n", $3,$4,$1);
    }
  ' xmltv.dat
}


#--------------------------------------------------------------------------
usage()
{
  echo "Usage: updatedvb [-d|-r]"
  echo "  -r  Use radio times xmltv ids (for tv_grab_uk_rt)"
  echo "  -d  Use DVB xmltv ids         (for tv_grab_dvb)"
}

#--------------------------------------------------------------------------

case "$1" in
  "-r") setchan_rt  | mysql -D mythconverg;;
  "-d") setchan_dvb | mysql -D mythconverg;;
  *)    usage;;
esac


