[mythtvnz] Manipulating Program Guide Information

Corrin Lakeland mythtvnz@lists.linuxnut.co.nz
Wed, 22 Feb 2006 13:02:28 +1300


On Tuesday 21 February 2006 19:14, Steven Ellis wrote:

> The DVB-T card has priority, and even though TV3 & 4 were marked as not
> visible for it, the scheduler would still try and use that tuner. Hence
> i'd like to get XML TV feeds that only contain the data I want.
>
> Plus if I use the hairy.geek.nz there are a lot of stations i'd like to
> strip out.
>
> Look like tv_grep will do most of what I want. Just working on a script
> at the moment.

The scripts I use provide you with what you are asking for.  Note that I think 
I'm doing it the wrong way and have been meaning to swap to setting visible 
instead :-)


Some comments:
	I'm using wget since curl always adds a Pragma: no-cache
	More efficient methods would be possible, even easier, these scripts just 
evolved this way.
	Sorry about the crude perl

Corrin

lakeland@dango:/usr/local/bin$ cat tv_grab_sky
#!/bin/bash -x
# grab xml tv listings from hairy.geek.nz
# and manipulate them so they look like the mr.geek.nz ones
#####################################################################
mkdir /tmp/epg
cd /tmp/epg
#remove old file
rm -f sky.xml.gz sky.xml

# get the file
wget --quiet --output-document sky.xml.gz 
http://hairy.geek.nz/epg/latest.xml.gz

# extract
gunzip sky.xml.gz


/usr/local/bin/add_mrgeek sky.xml > sky_tmp.xml && mv sky_tmp.xml sky.xml

#update mythtv database
mythfilldatabase --file 1 -1 /tmp/epg/sky.xml
chmod -R 777 /tmp/epg

lakeland@dango:/usr/local/bin$ cat tv_grab_tvnz
#!/bin/bash -x
# grab xml tv listings from hairy.geek.nz
# and manipulate them so they look like the mr.geek.nz ones
#####################################################################
mkdir /tmp/epg
cd /tmp/epg
#remove old file
rm -f tvnz.xml.gz tvnz.xml tvnz_tmp.xml

# get the file
wget --quiet --output-document tvnz.xml.gz 
http://hairy.geek.nz/epg/latest.xml.gz

# extract
gunzip tvnz.xml.gz

/usr/local/bin/add_mrgeek tvnz.xml > tvnz_tmp.xml && mv tvnz_tmp.xml tvnz.xml
/usr/local/bin/drop_sky tvnz.xml > tvnz_tmp.xml && mv tvnz_tmp.xml tvnz.xml

#update mythtv database
mythfilldatabase --file 1 -1 /tmp/epg/tvnz.xml
chmod -R 777 /tmp/epg

lakeland@dango:/usr/local/bin$ cat drop_sky
#!/usr/bin/perl

my $pre = 0;
my $chan = 1;
my $prog = 2;
my $post = 3;

my $print = 0;
my $skip = 1;

my $state = $pre;
my $do_print = $print;

print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
print "<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n";
print "<tv generator-info-name=\"dvb-epg-gen\">\n";

while (<>) {
        if (($pre == $state) && (/channel/)) {
                $state = $chan;
                $do_print = $print;
        }
        if (($chan == $state) && (/programme /)) {
                $state = $prog;
                $do_print = $print;
        }
        if (($prog == $state) && (/\<\/tv\>/)) {
                $state = $post;
                $do_print = $print;
        }

        if (($chan == $state) && (/mr.geek/)) {
                $do_print = $print;
        }
        if (($chan == $state) && (/dvb/)) {
                $do_print = $skip;
        }
        if (($prog == $state) && (/mr.geek/)) {
                $do_print = $print;
        }
        if (($prog == $state) && (/dvb/)) {
                $do_print = $skip;
        }

        print unless ($do_print == $skip);
}

lakeland@dango:/usr/local/bin$ cat add_mrgeek
#!/usr/bin/perl

# Change channels to something distinctive

while (<>) {
#       chomp;
# Change channel one
        s/1035.dvb.guide/TV1.mr.geek.nz/g;
        s/1037.dvb.guide/TV1.mr.geek.nz/g;
# Change channel two
        s/1036.dvb.guide/TV2.mr.geek.nz/g;
        s/1038.dvb.guide/TV2.mr.geek.nz/g;
# Change channel three
        s/1033.dvb.guide/TV3.mr.geek.nz/g;
# Change channel four
        s/1034.dvb.guide/TV4.mr.geek.nz/g;
#PRIME
        s/1018.dvb.guide/Prime.mr.geek.nz/g;
#Maori TV
        s/1025.dvb.guide/maori.mr.geek.nz/g;
        print;
}