[mythtvnz] DVB-T MHEG EPG

Tony Sauri hoiho.nz at gmail.com
Mon Apr 12 06:04:14 BST 2010


On Mon, 12 Apr 2010 16:15, Jason Taylor wrote:
> Is text in the guide in MHEG-5 guide absolutely positioned or some thing?
>
> I was under the impression that it was a csv file in the stream.. at
> least in england?
>

I didn't want to leap in here till I had a clear story for everyone but I can 
confirm that there is structured programme data in the mheg stream and it can 
be extracted much like epgsnoop and then massaged into xmltv format

I am currently experimenting, developing  and testing an epgsnoop like system
that is very raw at the moment and full of hard code but if anyone wants to 
get their hands dirty this is what I have at the moment.


First thing is to get a copy of rb-download:   look for RedButton at 
sourceforge.

Then run this perl proc to capture the data onto your hard drive
Locally I call this module mhegsnoop.pl

Note that internally this proc uses a python module Myth_Test_DVB-T_Card.py 
that has been hacked from something Hads (I think) did for the epgsnoop 
system.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/perl -w

# PERL MODULES WE WILL BE USING

    use POSIX ":sys_wait_h";


sub RunTime;

my $commontimestamp = time();
my $YYYYMMDD = RunTime;
$serviceid = 1200;
$parentcount = 0;
$kid = 0;
$free_adapter = "";
$sleep_interval = 0; #seconds
do
{
        sleep $sleep_interval;
        $sleep_interval = 600; #seconds or 10 mins.  If noadapter is available 
try again in 10 mins
        $encoder = 0;
        foreach $loopvar ( 0, 1)
        {
                $encodera = ++$encoder;
                $encoderb = ++$encoder;
                $encoderc = ++$encoder;
                $encoderd = ++$encoder;
                if (`Myth_Test_DVB-T_Card.py  $encodera $encoderb $encoderc 
$encoderd 2> /dev/null` eq "FREE\n")
                {
                        $free_adapter = $loopvar;
                        last;
                }
        }
} until $free_adapter ne "";

setpgrp(0,0);
if ($pid = fork)
{
        do
        {
                $parentcount++;
                sleep 3;
                $percentcomplete = $parentcount * 10 . "%";
                print "EPG Download $percentcomplete Complete\n";
        } until $parentcount == 10;   # 3 x 10 = 30 secs   till we kill 
rb-download
        sleep 2;
        local $SIG{HUP} = 'IGNORE';  # Don't kill ourselves
        kill(HUP, -$$);              # But kill all tasks we may have spawned
        do
        {
                $kid = waitpid($pid,&WNOHANG);
        } until $kid == -1;

}
else
{
        defined($pid)   or die "fork:   $!";
        sleep 3;
        `mkdir /home/tartarus/mheg_data_$YYYYMMDD`;
        system "/home/tartarus/rb-download -a $free_adapter 
-b /home/tartarus/mheg_data_$YYYYMMDD -f /home/tartarus/channels.conf 
$serviceid > /dev/null 2>&1";
}

exit 0;


sub RunTime

{
        my $sec = "";
        my $min = "";
        my $hour = "";
        my $mday = "";
        my $mon = "";
        my $year = "";
        my $wday = "";
        my $yday = "";
        my $isdst = "";
        my @dow = qw(Sun Mon Tue Wed Thu Fri Sat);
        my @moy = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 
localtime($commontimestamp);
        return sprintf("%04d", ($year + 1900)) . sprintf("%02d", ($mon + 1)) . 
sprintf("%02d", $mday);
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Finally to peek into the data use this perl proc


This really is raw and you will have to massage file names etc to make it work

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/perl
#
use File::stat;
$max_element_count = 0;
opendir(DIR, "/home/tartarus/mheg_data_20100412/services/1200/epg/data");
@date_files = grep { /\d+$/ } readdir(DIR);
closedir(DIR);
#print @date_files;
@date_files_sorted = sort {$a <=> $b} @date_files;
foreach $date_file (@date_files_sorted)
{

        opendir(DIR, 
"/home/tartarus/mheg_data_20100412/services/1200/epg/data/$date_file");
        @service_files = grep { /\d+$/ } readdir(DIR);
        closedir(DIR);
        @service_files_sorted = sort {$a <=> $b} @service_files;
        print @service_files_sorted;
        foreach $service_file (@service_files_sorted)
        {
                print "$date_file   $service_file\n";
                $filepath = 
"/home/tartarus/mheg_data_20100412/services/1200/epg/data/$date_file/$service_file";
                $sb = stat($filepath);
                $e = $sb->size;
                print "$e \n";
                #{ local $/ = undef;
                #}
                open (DATAFILE, "< $filepath") or die "cant open $file: $!";
                read(DATAFILE, $buffer, $sb->size);
                close(DATAFILE);
                @data_elements = split(/\x1c/, $buffer);
                $channel_rec = shift(@data_elements);
                print "$channel_rec\n";
                @channel_elements = split(/\x1d/, $channel_rec);
                $element_count = 0;
                foreach $channel_element (@channel_elements)
                {
                        $element_count++;
                        if ($element_count > $max_element_count)
                        {
                                $max_element_count = $element_count;
                        }
                #       print "$element_count ::: $channel_element \n";
                }
                $buffer =~ s/\n/\:\:/g;
                $buffer =~ s/\r/\n\t/g;
                $buffer =~ s/\x1c/\n/g;
                $buffer =~ s/\x1d/\n\t/g;
                print "$buffer";
        }
}
print "$max_element_count\n";
exit;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Regards

Tony Sauri



More information about the mythtvnz mailing list