[mythtv-users] current procedure for TV listings in the UK?

Nick Craig-Wood nick at craig-wood.com
Mon Sep 20 06:05:52 EDT 2004

On Mon, Sep 20, 2004 at 09:04:09AM +0100, Ashley Bostock wrote:
> How do you get the tv_grab_uk_dvb script to work properly?  If I run
> it I can generate an xml file with all the program data but there are
> 2 problem with it:
> 1) None of the channel IDs match with the xmltv ones, so instead of
> something like "south.bbc1.bbc.co.uk" I get "8139.dvb.guide", It says
> in the readme that you need to put a channels.conf file in the current
> dir, but how would this map to the correct xmltv names?

It doesn't.

> - Do I need to alter my database values to use 8139.dvb.guide instead
> of the xmltv IDs?

You can do that.  If you search the list archives you can find a PHP?
program to do that...

Alternatively you can use this script which I wrote which adjusts the
XML instead.  Note the service ids must be set correctly in your

It reads from stdin to stdout in the unix tradition!

#!/usr/bin/perl -w

# This converts the XML file from tv_grab_dvb to have xmltvids in it
# as per the myth database.
# by Nick Craig-Wood <nick at craig-wood.com>

use strict;
use DBI;

my $config = {};
open(CONFIG, "<$ENV{HOME}/.mythtv/mysql.txt") or open(CONFIG, "</etc/mythtv/mysql.txt")
    or die "Couldn't open myttv config at $ENV{HOME}/.mythtv/mysql.txt or /etc/mythtv/mysql.txt: $!";
while (<CONFIG>)
    $config->{$1} = $2 if /^(\w+)=(.*)$/;
close CONFIG or die "Error closing config: $!";

my $HOST = $config->{DBHostName} || "localhost";
my $USER = $config->{DBUserName} || "mythtv";
my $DB   = $config->{DBName}     || "mythconverg";
my $PASS = $config->{DBPassword} || "mythtv";

my $dbh = DBI->connect( "DBI:mysql:database=$DB;host=$HOST", $USER, $PASS, { RaiseError => 1 });
die "Failed to connect to database" unless defined $dbh;

my $find_row = $dbh->prepare("select serviceid,xmltvid from channel,dvb_channel where channel.chanid=dvb_channel.chanid");
my $id = {};
while (my $row = $find_row->fetchrow_hashref)
    die "xmltvid not defined" unless defined $row->{xmltvid};
    die "serviceid not defined" unless defined $row->{serviceid};
    $id->{"\"$row->{serviceid}.dvb.guide\""} = "\"$row->{xmltvid}\"";


# Make regexp for replacement
my $re = "(" . join("|", map { quotemeta($_) } sort keys %$id) .")";

# Filter the input file through tv_grep
my $filter = join (" --or ", map { "--channel-id $_" } sort values %$id);
open(TV_GREP, "|tv_grep $filter") or die "Failed to open tv_grep: $!";

# Search and replace input file
while (<>)
    print TV_GREP $_;

close(TV_GREP) or die "Failed to close tv_grep: $!";

> 2) The generated xml file seems to contain data for categories but
> they dont seem to match the corresponding mythtv names, the only
> category that seemed to show up in the epg was sport.
> Any ideas?

I patched my tv_grab_dvb, but the correct way would be to patch mythtv.
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick

More information about the mythtv-users mailing list