-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_identifiers.pl
executable file
·147 lines (125 loc) · 3.02 KB
/
update_identifiers.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl -w
use strict;
use HTML::Entities qw(decode_entities);
use HTML::TableExtract;
require HTTP::Request;
require LWP::UserAgent;
sub trim {
@_ = $_ if not @_ and defined wantarray;
@_ = @_ if defined wantarray;
for (@_ ? @_ : $_) {
if (defined $_) {
s/\xC2\xA0//;
s/\x96/-/g;
s/^[“\s]+//;
s/[-”\s]+$//;
s/^\((.*)\)$/$1/;
s/"/\\"/g;
}
}
return wantarray ? @_ : $_[0] if defined wantarray;
}
sub fetch {
my $type = shift;
my $req = HTTP::Request->new(GET => "http://www.dvb.org/products_registration/dvb_identifiers/identifiers.xml?type=" . $type);
#my $req = HTTP::Request->new(GET => "file:" . $type . ".html");
my $ua = LWP::UserAgent->new;
my $rsp = $ua->request($req);
die $rsp->status_line unless ($rsp->is_success);
return decode_entities($rsp->decoded_content);
}
sub parse_table {
my $type = shift;
my $page = fetch($type);
my $te = HTML::TableExtract->new( headers => [ "ID/Range", @_ ] );
$te->parse($page);
# don't know the correct syntax to return the first element
foreach my $ts ($te->tables) {
return $ts;
}
}
sub update {
my $t = parse_table(@_);
open(OUT, ">src/strings/identifiers/" . $_[0] . ".h");
binmode(OUT, ":encoding(utf8)");
foreach my $row ($t->rows) {
my ($id, @fields) = trim @$row;
$id =~ s/\s//g;
if ($id =~ m/(0x[0-9a-fA-F]+)-(0x[0-9a-fA-F]+)/) {
if (oct($2) < oct($1)) {
print OUT "//";
}
print OUT "{ $1, $2, \"";
} else {
print OUT "{ $id, $id, \"";
}
for my $i (0 ... @fields - 1) {
if (defined $fields[$i]) {
print OUT $fields[$i];
$i++;
if (($i < @fields) and (defined $fields[$i])) {
print OUT " | ";
}
} else {
$i++;
}
}
print OUT "\" },\n";
}
print OUT "{ 0, 0, NULL }\n";
close(OUT);
}
sub bouquetID {
update("bouquetID", "Name", "Country Code", "Operator");
}
sub caSystemID {
update("caSystemID", "CA System specifier");
}
sub cpSystemID {
update("cpSystemID", "CP System specifier");
}
sub dataBroadcastID {
update("dataBroadcastID", "Data Broqadcast Specification Name");
}
sub networkID {
update("networkID", "Description", "Country Code", "Network Type", "Operator");
}
sub originalNetworkID {
update("originalNetworkID", "Description", "Operator");
}
sub privateDataSpecifierID {
update("privateDataSpecifierID", "Organisation");
}
sub platformID {
update("platformID", "Platform Name", "Operator");
}
sub rootOfTrustID {
update("rootOfTrustID", "Description", "Operator");
}
sub mhpOrganisationID {
update("mhpOrganisationID", "Organisation Supplying MHP Applications");
}
sub mhpApplicationTypeID {
update("mhpApplicationTypeID", "Description", "Operator");
}
sub mhpAITDescriptors {
update("mhpAITDescriptors", "Description", "Operator");
}
sub mhpProtocolID {
update("mhpProtocolID", "Description");
}
# DVB-SI Identifiers
bouquetID();
caSystemID();
cpSystemID();
dataBroadcastID();
networkID();
originalNetworkID();
privateDataSpecifierID();
platformID();
rootOfTrustID();
# MHP Identifiers
mhpOrganisationID();
mhpApplicationTypeID();
mhpAITDescriptors();
mhpProtocolID();