[mythtv-users] BBC THREE/FOUR
Malcolm Smith
malc at porsche.demon.co.uk
Wed Feb 4 06:22:26 EST 2004
Kenneth,
Here's the PERL that does this.....(I have to credit Daniel with the
major chunk of the code)
Can anyone turn this into a Qt / C++ thingy?
-malc-
Kenneth Aafløy wrote:
>Simon wrote:
>
>>Malcolm Smith wrote:
>>
>>>I would check your pids. I've been working with Daniel on a
>>>script that takes the output of scan and loads up the various
>>>tables. I could let you have a copy. (It's not complete yet).
>>>
>>That would be the most obvious solution.. Might I suggest for
>>a future direction that the mythtv setup program be enhanced
>>to allow a external tuner application to be run to do this.
>>That way it should be possible to automate the process for
>>other DVB types and even analog if somebody knocks together
>>the scan/detection app.
>>
>
>I have always had `in house` code in mind. If someone would
>write simple code to parse/import the vdr .conf files it's
>acceptable, and even a extra feature. It should be really
>simple to write also, since it's just a bounch of :::::::::'s
>and newlines + the parameter wording. I might consider helping
>with a rewrite of the parsers in DVBChannel and DB if someone
>writes the logic for setup.
>
>If this get's done, all someone have to do is scan before
>running mythsetup (verifying that the card works at the
>same time), and import the channel.conf. If someone already
>has a 1000+ line channel.conf from vdr, they could just
>import and be set :)
>
>Ciao,
>Kenneth
>
>
>_______________________________________________
>mythtv-users mailing list
>mythtv-users at mythtv.org
>http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
>
-------------- next part --------------
#!/usr/bin/perl -w
use strict;
use DBI();
use Getopt::Long;
use File::Basename;
# configuration
#my $channelsconf = "/root/.szap/channels.conf";
#my $channelsconf = "/usr/src/DVB/apps/szap/channels.conf-dvbt-oxford";
my $channelsconf = "channels.conf";
# type of channels.conf file
# for now szap or tzap
my $channelsconftype = "tzap";
my $satid = 1;
my $inversion="a";
my $sourceid = 1;
# wether to ask for or not
my $ask_transportid = 1;
my $ask_networkid = 1;
my $ask_serviceid = 1;
my $ask_tpid = 1;
my $ask_modulation = 1;
my $sql1="Invalid";
# do nothing
my $simulate = 1;
# variable definition
my $doinserts;
my $dofind;
my $networkid;
my $transportid;
my @channeldata;
my %channelhash;
my $db_host;
my $db_user;
my $db_name;
my $db_pass;
# Read the mysql.txt file in use by MythTV.
# could be in a couple places, so try the usual suspects
open(CONF, "/usr/share/mythtv/mysql.txt")
or open(CONF, "/usr/local/share/mythtv/mysql.txt")
or die ("Unable to open /usr/share/mythtv/mysql.txt: $!\n\n");
while (my $line = <CONF>) {
chomp($line);
$line =~ s/^str //;
my ($var, $val) = split(/\=/, $line, 2);
next unless ($var && $var =~ /\w/);
if ($var eq 'DBHostName') {
$db_host = $val;
}
elsif ($var eq 'DBUserName') {
$db_user = $val;
}
elsif ($var eq 'DBName') {
$db_name = $val;
}
elsif ($var eq 'DBPassword') {
$db_pass = $val;
}
}
close CONF;
# Connect to the database
my $dbh = DBI->connect("dbi:mysql:database=$db_name:host=$db_host", $db_user, $db_pass)
or die "Cannot connect to database: $!\n\n";
if ($simulate) {
print "Simulation mode. SQL not done.\n";
};
# Now retrieve data from the channel table.
my $tb_channel = $dbh->prepare("SELECT * FROM channel WHERE sourceid=$sourceid");
$tb_channel->execute();
while (my $ref = $tb_channel->fetchrow_hashref()) {
$dofind = 0;
print "\nFound a row: chanid = $ref->{'chanid'}, name = $ref->{'name'}\n";
# search corresponding rows in dvb_channel
my $tb_dvb_channel = $dbh->prepare("SELECT * FROM dvb_channel WHERE chanid=" . $ref->{'chanid'});
my $count_dvbchannel = $tb_dvb_channel->execute();
if ($count_dvbchannel >= 1) {
# channel already exists in dvb_channel
print "Found $count_dvbchannel corresponding row(s) in dvb_channel table\n";
# integrity check: there have to be at least two rows in dvb_pids
my $tb_dvb_pids = $dbh->prepare("SELECT * FROM dvb_pids WHERE chanid=" . $ref->{'chanid'});
my $count_dvbpids = $tb_dvb_pids->execute();
if ($count_dvbpids < 2) {
print "Warning: Less than 2 dvb_pids not found\n";
}
print "Do you want to re-insert? [n]/y:";
my $selection = <>;
chomp($selection);
if ($selection eq "y" ) {
$dofind = 1 ;
}
$tb_dvb_pids->finish();
} else {
# no corresponding row in dvb_channel, so let's insert data
print "no corresponding row in dvb_channel, need data, searching channels.conf\n";
$dofind = 1;
}
if ($dofind) {
open (CHANNELSCONF, "cat $channelsconf | grep -i \"" . $ref->{'name'} . "\" |") or die "failed opening channels.conf: $!";
my @channelsconf = <CHANNELSCONF>;
close CHANNELSCONF;
my $channelsconfrows=$#channelsconf + 1;
if ( $channelsconfrows == 0 ) {
print "Zero rows found. Do you want to enter a search term? [n]/y:";
my $selection = <>;
chomp($selection);
if ($selection eq "y" ) {
print "Enter search term:";
$selection = <>;
chomp($selection);
open (CHANNELSCONF, "cat $channelsconf | grep -i \"" . $selection . "\" |") or die "failed opening channels.conf: $!";
@channelsconf = <CHANNELSCONF>;
close CHANNELSCONF;
$channelsconfrows=$#channelsconf + 1;
}
}
print "found $channelsconfrows matching rows in channels.conf\n";
for (my $i = 1; $i < $channelsconfrows + 1; $i++) {
print "$i: " . $channelsconf[$i-1] . "\n";
}
print "What to do [number (use one of the above), i (ignore), m (manually enter)]? ";
my $selection = <>;
chomp($selection);
#print $selection . "\n";
if ($selection =~ /^\d+$/) {
print "using row $selection\n";
# get the information out of the channelsconf row
@channeldata=split(/:/, $channelsconf[$selection-1]);
# extract the data out of the channelsconf row
if ($channelsconftype eq 'szap') {
$channelhash{'frequency'} = $channeldata[1] . '000';
$channelhash{'polarity'} = $channeldata[2];
$channelhash{'symbolrate'} = $channeldata[4] . '000';
$channelhash{'vpid'} = $channeldata[5];
$channelhash{'apid'} = $channeldata[6];
$channelhash{'serviceid'} = $channeldata[8];
# on dvb-s we always have qpsk
$channelhash{'modulation'} = 'qpsk';
} elsif ($channelsconftype eq 'tzap') {
$channelhash{'frequency'} = $channeldata[1];
$channelhash{'inversion'} = $channeldata[2];
$channelhash{'fec_1'} = $channeldata[4];
$channelhash{'fec_2'} = $channeldata[5];
$channelhash{'transmissionmode'} = $channeldata[7];
$channelhash{'guardinterval'} = $channeldata[8];
$channelhash{'hierarchy'} = $channeldata[9];
$channelhash{'vpid'} = $channeldata[10];
$channelhash{'apid'} = $channeldata[11];
$channelhash{'tpid'} = $channeldata[12] if defined($channeldata[12]);
$channelhash{'modulation'} = $channeldata[6];
# make modulation lowercase
$channelhash{'modulation'} =~ s/QAM/qam/g;
$channelhash{'fec_1'} =~ s/FEC_//g;
$channelhash{'fec_1'} =~ s/_/\//g;
$channelhash{'fec_2'} =~ s/FEC_//g;
$channelhash{'fec_2'} =~ s/_/\//g;
$channelhash{'guardinterval'} =~ s/GUARD_INTERVAL_//g;
$channelhash{'guardinterval'} =~ s/_/\//g;
$channelhash{'tpid'} =~ s/$/ /g;
chomp($channelhash{'apid'});
# Set polarity and symbolrate here to defaults
$channelhash{'polarity'} = 'V';
$channelhash{'symbolrate'} = '69000';
$channelhash{'transmissionmode'} =~ s/TRANSMISSION_MODE_//g;
$channelhash{'transmissionmode'} =~ s/K//g;
if ($channelhash{'inversion'} eq "INVERSION_OFF" ) {
$channelhash{'inversion'} = '0' } else {
$channelhash{'inversion'} = '1'
};
if ($channelhash{'hierarchy'} eq "HIERARCHY_NONE" ) {
$channelhash{'hierarchy'} = 'n' } else {
$channelhash{'hierarchy'} = 'auto'
}
$ask_transportid = 0;
$ask_networkid = 0;
$ask_serviceid = 0;
}
print "fec_1: " . $channelhash{'fec_1'} . "\n";
print "fec_2: " . $channelhash{'fec_2'} . "\n";
print "inversion: " . $channelhash{'inversion'} . "\n";
print "transmissionmode: " . $channelhash{'transmissionmode'} . "\n";
print "guardinterval: " . $channelhash{'guardinterval'} . "\n";
print "hierarchy: " . $channelhash{'hierarchy'} . "\n";
print "chanid: " . $ref->{'chanid'} . "\n";
print "frequency: $channelhash{'frequency'}\n";
print "polarity: $channelhash{'polarity'}\n";
print "symbolrate: $channelhash{'symbolrate'}\n";
print "modulation: $channelhash{'modulation'}\n";
print "VPID: $channelhash{'vpid'}\n";
print "APID: $channelhash{'apid'}\n";
if ( (($channelsconftype eq 'tzap') and defined($channeldata[12])) or ($ask_tpid == 0) ) {
if ($ask_tpid == 0) {
$channelhash{'tpid'} = 0;
print "WARNING: tpid will not be inserted in dvb_pids.\n";
}
print "TPID: $channelhash{'tpid'}\n";
} else {
print "TPID: ";
$channelhash{'tpid'}=<>;
chomp ($channelhash{'tpid'});
}
if (($ask_serviceid) and ($channelsconftype eq 'tzap')) {
# ask for serviceid if $ask_serviceid is set and we don't have it from the channels.conf
print "serviceid: ";
$channelhash{'serviceid'}=<>;
chomp ($channelhash{'serviceid'});
} else {
if ($channelsconftype eq 'tzap') {
# set a default value if we don't have it from channels.conf and $ask_serviceid is not set
$channelhash{'serviceid'} = 0;
}
print "serviceid: $channelhash{'serviceid'}\n";
}
if ($ask_transportid) {
print "transportid: ";
$channelhash{'transportid'}=<>;
chomp ($channelhash{'transportid'});
} else {
$channelhash{'transportid'} = '0';
print "transportid: $channelhash{'transportid'}\n";
}
if ($ask_networkid) {
print "networkid: ";
$channelhash{'networkid'}=<>;
chomp ($channelhash{'networkid'});
} else {
$channelhash{'networkid'} = '0';
print "networkid: $channelhash{'networkid'}\n";
}
$doinserts=1;
} elsif ($selection eq "m") {
# enter information manually
print "chanid: " . $ref->{'chanid'} . "\n";
print "frequency: ";
$channelhash{'frequency'}=<>;
chomp($channelhash{'frequency'});
if ($channelsconftype eq 'szap') {
print "polarity (lowercase): ";
$channelhash{'polarity'}=<>;
chomp($channelhash{'polarity'});
print "symbolrate (5 digits): ";
$channelhash{'symbolrate'}=<>;
chomp($channelhash{'symbolrate'});
# adjust data for use with mythtv
$channelhash{'symbolrate'} = $channelhash{'symbolrate'} . "000";
} else {
# we don't need this for dvb-t
$channelhash{'polarity'} = '';
$channelhash{'symbolrate'} = 0;
}
if ($ask_modulation) {
print "modulation (qpsk, qam_xx): ";
$channelhash{'modulation'}=<>;
chomp ($channelhash{'modulation'});
} else {
$channelhash{'modulation'} = '';
print "modulation: $channelhash{'modulation'}\n";
}
print "VPID: ";
$channelhash{'vpid'}=<>;
chomp($channelhash{'vpid'});
print "APID: ";
$channelhash{'apid'}=<>;
chomp($channelhash{'apid'});
if ($ask_tpid) {
print "TPID: ";
$channelhash{'tpid'}=<>;
chomp ($channelhash{'tpid'});
} else {
$channelhash{'tpid'} = '0';
print "TPID (will not be inserted in dvb_pids): $channelhash{'tpid'}\n";
}
if ($ask_serviceid) {
print "serviceid: ";
$channelhash{'serviceid'}=<>;
chomp ($channelhash{'serviceid'});
} else {
$channelhash{'serviceid'} = '0';
print "serviceid: $channelhash{'serviceid'}\n";
}
if ($ask_transportid) {
print "transportid: ";
$channelhash{'transportid'}=<>;
chomp ($channelhash{'transportid'});
} else {
$channelhash{'transportid'} = '0';
print "transportid: $channelhash{'transportid'}\n";
}
if ($ask_networkid) {
print "networkid: ";
$channelhash{'networkid'}=<>;
chomp ($channelhash{'networkid'});
} else {
$channelhash{'networkid'} = '0';
print "networkid: $channelhash{'networkid'}\n";
}
$doinserts=1;
} else {
$doinserts=0;
}
if ($doinserts==1) {
# insert1: dvb_channel
if ($channelsconftype eq 'szap') {
$sql1 = "REPLACE INTO dvb_channel (chanid, serviceid, networkid, transportid, frequency, inversion, symbolrate, polarity, satid, modulation) " .
"VALUES (" . $ref->{'chanid'} . ", $channelhash{'serviceid'}, $channelhash{'networkid'}, $channelhash{'transportid'}, " .
"$channelhash{'frequency'}, \'$inversion\', $channelhash{'symbolrate'}, \'$channelhash{'polarity'}\', $satid, \'$channelhash{'modulation'}\');";
}
if ($channelsconftype eq 'tzap') {
print "channel type" . $channelsconftype . "\n";
$sql1 = "REPLACE INTO dvb_channel (chanid, serviceid, networkid, transportid, frequency, inversion, symbolrate" .
", fec, polarity, modulation, hp_code_rate , lp_code_rate, transmission_mode, guard_interval, hierarchy) " .
"VALUES (" . $ref->{'chanid'} . ", $channelhash{'serviceid'}, $channelhash{'networkid'}, $channelhash{'transportid'}, " .
"$channelhash{'frequency'}, \'$inversion\', \'$channelhash{'symbolrate'}\', \'$channelhash{'fec_1'}\', \'$channelhash{'polarity'}\'," .
" \'$channelhash{'modulation'}\' , \'$channelhash{'fec_1'}\', \'$channelhash{'fec_2'}\', \'$channelhash{'transmissionmode'}\', \'$channelhash{'guardinterval'}\', \'$channelhash{'hierarchy'}\');";
}
#insert2: vpid
my $sql2 = "REPLACE INTO dvb_pids (chanid, pid, type) VALUES (" . $ref->{'chanid'} . ", $channelhash{'vpid'}, \'v\');";
#insert3: apid
my $sql3 = "REPLACE INTO dvb_pids (chanid, pid, type) VALUES (" . $ref->{'chanid'} . ", $channelhash{'apid'}, \'a\');";
#insert4: tpid
my $sql4 = "REPLACE INTO dvb_pids (chanid, pid, type) VALUES (" . $ref->{'chanid'} . ", $channelhash{'tpid'}, \'t\');";
print "Generated SQL sql1: \n$sql1\n";
print "Generated SQL sql2: \n$sql2\n";
print "Generated SQL sql3: \n$sql3\n";
print "Generated SQL sql4: \n$sql4\n";
if ($simulate) {
print "Simulation mode. SQL not done.\n";
} else {
$dbh->do($sql1);
$dbh->do($sql2);
$dbh->do($sql3);
if ($ask_tpid == 1) {
$dbh->do($sql4);
}
print "SQL insert complete.\n";
}
}
}
$tb_dvb_channel->finish();
}
$tb_channel->finish();
$dbh->disconnect();
More information about the mythtv-users
mailing list