DVB-Epg
view release on metacpan or search on metacpan
lib/DVB/Epg.pm view on Meta::CPAN
# add program to EIT for which to generate EPG
$myEpg->addEit( 18, 9019, 1024, 15, 8, 1);
# add dummy event data to database
my $event = {};
$event->{start} = time;
$event->{stop} = time+100;
$event->{uid} = 15;
$myEpg->addEvent( $event);
# generate EPG tables to database
$myEpg->updateEit( 18);
# export EIT as MTS from database
my $mts = $myEpg->getEit( 18);
The Library can handle multiple services and multiple tables.
=head1 CLASS C<Epg>
=head2 METHODS
=cut
package DVB::EventInformationTable;
package DVB::Epg;
use 5.010;
use strict;
use warnings;
use utf8;
use DBI qw(:sql_types);
use Storable qw(freeze thaw);
use Carp;
use Exporter;
use POSIX qw(ceil);
use vars qw($VERSION @ISA @EXPORT);
our $VERSION = "0.51";
our @ISA = qw(Exporter);
our @EXPORT = qw();
=head3 new( $dbfile )
Class initialization with sqlite3 database filename.
Open existing or create new sqlite database.
=cut
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = {};
$self->{filename} = shift;
$self->{dbh} = DBI->connect( "dbi:SQLite:" . $self->{filename} ) or return;
$self->{dbh}->{sqlite_unicode} = 1;
$self->{dbh}->do( "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA auto_vacuum = NONE; PRAGMA cache_size = 4000000; " );
bless( $self, $class );
return $self;
}
=head3 dbh( )
Return database handle for direct control.
=cut
sub dbh {
return $_[0]->{dbh};
}
=head3 initdb( )
Initialize database with some basic table structure;
=cut
sub initdb {
my $self = shift;
my $dbh = $self->{dbh};
$dbh->do("BEGIN TRANSACTION");
$dbh->do( "DROP TABLE IF EXISTS event");
$dbh->do( "DROP TABLE IF EXISTS eit");
$dbh->do( "DROP TABLE IF EXISTS eit_version");
$dbh->do( "DROP TABLE IF EXISTS section");
$dbh->do( "CREATE TABLE event ( event_id INTEGER,
uid INTEGER,
start DATE,
stop DATE,
info BLOB,
timestamp DATE,
PRIMARY KEY( uid, event_id))");
$dbh->do( "CREATE TABLE eit ( pid INTEGER,
service_id INTEGER,
original_network_id INTEGER,
transport_stream_id INTEGER,
uid INTEGER,
maxsegments INTEGER,
actual INTEGER,
comment TEXT,
PRIMARY KEY( pid, original_network_id, transport_stream_id, service_id))");
$dbh->do( "CREATE TABLE eit_version ( pid INTEGER,
service_id INTEGER,
table_id INTEGER,
version_number INTEGER,
timestamp DATE,
PRIMARY KEY( pid, service_id, table_id))");
$dbh->do( "CREATE TABLE section ( pid INTEGER,
table_id INTEGER,
( run in 0.613 second using v1.01-cache-2.11-cpan-39bf76dae61 )