comparison src/epgdump_xml_parse.pl @ 150:036ae90f1b01

EXPERIMENTAL: Add channel scan script. require: epgdump, XML::Simple
author Naoya OYAMA <naoya.oyama@gmail.com>
date Fri, 31 Aug 2012 05:12:44 +0900
parents
children 2c1cec3c5d64
comparison
equal deleted inserted replaced
149:a9f60d56d673 150:036ae90f1b01
1 #!/usr/bin/perl -w
2 # epgdmp_xml_parse.pl -- parse epgdump XML file.
3 #
4 # Copyright 2012 Naoya OYAMA <naoya.oyama@gmail.com>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 use strict;
20 use XML::Simple;
21
22 my $simple = XML::Simple->new (ForceArray => 1, KeepRoot => 1);
23 my $data = $simple->XMLin($ARGV[0]);
24
25 my @base = @{$data->{tv}};
26 my %tv = %{$base[0]};
27 my %channels = %{$tv{channel}};
28 my %channel_info_list = ();
29 my @service_id_list = ();
30
31 while (my ($channelType, $channelRef) = each %channels) {
32 my %channel = %$channelRef;
33 my $service_id = $channel{service_id};
34 my @si = ();
35 my %sih = ();
36 my $tp = "";
37
38 if (defined($channel{satelliteinfo})) {
39 @si = @{$channel{satelliteinfo}};
40 %sih = %{$si[0]};
41 $tp = $sih{TP}[0];
42 if($tp =~ m/^BS\d+$/) {
43 $tp = $service_id;
44 }
45 } else {
46 $tp = $ARGV[0];
47 $tp =~ s/^.*\/(\d+)\.xml$/$1/;
48 }
49 my @dpna = @{$channel{"display-name"}};
50 my %dpnh = %{$dpna[0]};
51
52 $channel_info_list{$service_id}{SID} = $service_id;
53 $channel_info_list{$service_id}{TP} = $tp;
54 $channel_info_list{$service_id}{NAME} = $dpnh{content};
55 push(@service_id_list, $service_id);
56 }
57
58 foreach my $service_id (sort {$a <=> $b} @service_id_list) {
59 print $channel_info_list{$service_id}{SID} . ",";
60 print $channel_info_list{$service_id}{TP} . ",";
61 print $channel_info_list{$service_id}{NAME} . "\n";
62 }
63 1;