Augmenter: use warnings
[nonametv.git] / tools / de / nonametv-xmltv-genhtml
blobb365277acc165f230fb3049e5d57d54c73437318
1 #!/usr/bin/perl -w
3 use strict;
5 use FindBin;
6 use lib "$FindBin::Bin/../../lib";
8 use NonameTV::Factory qw/CreateDataStore/;
10 use File::Copy;
12 # How large an empty xmltv-file can be.
13 use constant EMPTY_SIZE => 140;
15 if( scalar( @ARGV ) != 2 )
17 print << 'EODOC';
18 nonametv-xmltv-genhtml <outputdir> <installationdir>
20 Generate a table with data for each day and channel. The .xml.gz-files
21 should be located in <dir> and the table will be written to
22 <dir>/00index.html.
24 <installationdir> should be the basedir for a nonametv installation.
26 Furthermore, the program generates a file 00logos.html that contains
27 a list of all channels and shows their logos.
29 If the result of nonametv-xmltv-genhtml is identical to the previous
30 content of 00index.html, the original file will be left untouched.
32 EODOC
34 exit 1;
37 my( $dir, $installdir ) = @ARGV;
39 my $ds = CreateDataStore();
41 # Build list of files
42 my %files;
44 foreach my $file ( glob("$dir/*.xml.gz") )
46 my( $name ) = ($file =~ m%/([^/]+_\d{4}-\d{2}-\d{2}).xml.gz%);
47 $files{$name} = "X" if defined $name;
50 foreach my $file (keys %files)
52 if( -s( "$dir/$file.xml.gz" ) < EMPTY_SIZE )
54 # File is empty.
55 $files{$file} = "E";
56 next;
60 my @channels;
61 my %dates;
63 my $ch = $ds->sa->LookupMany( "channels", { export => 1 }, ['xmltvid'] );
65 foreach my $c (@{$ch}) {
66 push @channels, $c->{xmltvid};
69 foreach my $file (keys %files)
71 my( $channel, $date ) = split( "_", $file );
72 $dates{$date} = 1;
75 open OUT, "> $dir/00index.html.new"
76 or die "Failed to open output file: $@";
78 print OUT << "EOHEAD";
79 <html>
80 <head>
81 <style type="text/css">
82 .X { text-align: center; }
83 .E { text-align: center; background-color: grey; }
84 </style>
85 </head>
86 <body>
87 <h1>Schedules</h1>
88 <table>
89 <thead>
90 <tr>
91 <td>Channel</td>
92 EOHEAD
94 foreach my $date (sort keys %dates)
96 my( $s ) = ($date =~ m/(\d\d-\d\d)$/);
97 print OUT " <td>$s</td>\n";
100 print OUT << "EOD";
101 </tr>
102 </thead>
103 <tbody>
107 foreach my $channel (@channels)
109 print OUT << "EOD";
110 <tr>
111 <td>$channel</td>
115 foreach my $date (sort keys %dates)
117 my $file = "${channel}_$date";
118 $files{$file} = ' ' unless defined $files{$file};
120 if( $files{$file} eq 'U' )
122 print OUT "<td class='$files{$file}'><a href='$file.diff'>$files{$file}</a></td>";
124 else
126 print OUT "<td class='$files{$file}'><a href='displayfile.html?$file'>$files{$file}</a></td>";
130 print OUT "</tr>\n";
133 print OUT << "EOD";
135 </tbody>
136 </table>
137 </body>
138 </html>
142 close(OUT);
144 update_if_changed( "$dir/00index.html.new", "$dir/00index.html" );
146 open OUT, "> $dir/00logos.html.new"
147 or die "Failed to open output file: $@";
149 print OUT << "EOHEAD";
150 <html>
151 <head>
153 <script language="JavaScript">
154 function changeBg(col)
156 document.bgColor = col;
159 </script>
161 </head>
162 <body>
163 <h1>Logos</h1>
164 Background:
165 <a href="javascript:changeBg('#ffffff')">White</a>
166 <a href="javascript:changeBg('#dddddd')">Light grey</a>
167 <a href="javascript:changeBg('#333333')">Dark grey</a>
168 <a href="javascript:changeBg('#000000')">Black</a>
169 <a href="javascript:changeBg('#0000dd')">Dark blue</a>
171 <table>
173 EOHEAD
175 foreach my $channel (@channels)
177 print OUT << "EOREC";
178 <tr>
179 <td>$channel</td>
180 <td><img src="http://xmltv.spaetfruehstuecken.org/chanlogos/$channel.png"></td>
181 <td><img src="http://xmltv.spaetfruehstuecken.org/chanlogos/44x44/$channel.png"></td>
182 <td><img src="http://xmltv.spaetfruehstuecken.org/chanlogos/16x16/$channel.png"></td>
183 </tr>
185 EOREC
189 print OUT << "EOFOOT";
190 </table>
191 </body>
192 </html>
194 EOFOOT
196 close(OUT);
198 update_if_changed( "$dir/00logos.html.new", "$dir/00logos.html" );
200 system( "zcat $dir/channels.xml.gz | xsltproc $installdir/examples/channel-list.xsl - > $dir/channels.html.new" );
202 update_if_changed( "$dir/channels.html.new", "$dir/channels.html" );
204 sub update_if_changed {
205 my( $new, $old ) = @_;
207 system("diff $new $old > /dev/null 2>&1");
208 if( $? ) {
209 move( "$new", "$old" );
211 else {
212 unlink( "$new" );