Ticket #3640: mythic.pl

File mythic.pl, 1.9 KB (added by anonymous, 12 years ago)

Perl Script to fix all frequency data in channel and dtv_multiplex tables from channels.conf, fills in all columns from channels.conf including symbols per second, and removes all unreferenced multiplexes. To use load channels.conf into mythtv-setup as usual, optionally delete all channels and do a scan on all existing multiplexes, then run this script on the channels.conf.

Line 
1#!/usr/bin/env perl
2use utf8;
3use strict;
4use warnings;
5use DBI;
6use FileHandle;
7use enum qw(:Chan_=0 Name Freq Inv SymRate Fec Qam VID AID PID);
8
9if (scalar @ARGV != 1) {
10        print "usage: $0 <channels.conf>\n";
11        exit;
12}
13
14my %Inversion = (
15        INVERSION_AUTO => 'a',
16        INVERSION_ON => '1',
17        INVERSION_OFF => '0'
18);
19
20my %Fec = (
21        FEC_NONE => 'none',
22        FEC_1_2 => '1/2',
23        FEC_2_3 => '2/3',
24        FEC_3_4 => '3/4',
25        FEC_4_5 => '4/5',
26        FEC_5_6 => '5/6',
27        FEC_6_7 => '6/7',
28        FEC_7_8 => '7/8',
29        FEC_8_9 => '8/9',
30        FEC_AUTO => 'auto'
31);
32
33my %Qam = (
34        QPSK => 'qpsk',
35        QAM_16 => 'qam_16',
36        QAM_32 => 'qam_32',
37        QAM_64 => 'qam_64',
38        QAM_128 => 'qam_128',
39        QAM_256 => 'qam_256',
40        QAM_AUTO => 'auto',
41        '8VSB' => '8vsb',
42        '16VSB' => '16vsb'
43);
44
45my $dbh = DBI->connect('DBI:mysql:database=mythconverg','mythtv','mythtv') || die "$!\n";
46my $get_freq_by_name = $dbh->prepare('select freqid, mplexid from channel where name=? and channum=?') || die $dbh->errstr."\n";
47my $dvbc = new FileHandle($ARGV[0],'r') || die "$!\n";
48
49$dbh->do('delete from dtv_multiplex where mplexid not in (select distinct mplexid from channel)');
50
51while (my $chan = $dvbc->getline) {
52        $chan =~ s/^\s*//;
53        $chan =~ s/\s*$//;
54        my @chan = split(':',$chan);
55        $get_freq_by_name->execute($chan[Chan_Name],$chan[Chan_PID]);
56        if ($get_freq_by_name->rows == 1) {
57                my $row=$get_freq_by_name->fetchrow_hashref;
58                print "$chan[Chan_PID]:$chan[Chan_Name] $row->{'freqid'} => $chan[Chan_Freq]\n";
59                $dbh->do("update channel set freqid=".$dbh->quote($chan[Chan_Freq])
60                        ." where name=".$dbh->quote($chan[Chan_Name])
61                        ." and channum=".$dbh->quote($chan[Chan_PID])
62                );
63                $dbh->do("update dtv_multiplex set frequency=".$dbh->quote($chan[Chan_Freq])
64                        .", inversion=".$dbh->quote($Inversion{$chan[Chan_Inv]})
65                        .", symbolrate=".$dbh->quote($chan[Chan_SymRate])
66                        .", fec=".$dbh->quote($Fec{$chan[Chan_Fec]})
67                        .", modulation=".$dbh->quote($Qam{$chan[Chan_Qam]})
68                        .", sistandard='dvb'"
69                        ." where mplexid=".$dbh->quote($row->{'mplexid'})
70                );
71        }
72}
73