/[mplayer-eee-tv]/program/xmltv.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /program/xmltv.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (show annotations)
Sat Oct 31 13:10:05 2009 UTC (14 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 1769 byte(s)
convert xmltv into html table with vertical programs

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use XML::Simple;
7 use Data::Dump qw(dump);
8
9 my $tv = XMLin( 'tv.xml',
10 ContentKey => '-content',
11 );
12
13 warn dump $tv;
14
15 print qq|
16
17 <style type="text/css">
18
19 ,hour {
20 border-top: 1px dashed #ccc;
21 }
22
23 </style>
24
25 <table border=1 >
26 <tr><td></td>
27 |;
28
29 my @channels = keys %{ $tv->{channel} };
30 warn "# channels ",dump @channels;
31
32 print qq|<th><img src="|, $_->{'icon'}->{'src'}, qq|"><br>|, $_->{'display-name'}->{'content'}, qq|</th>| foreach map { $tv->{channel}->{$_} } @channels;
33
34 print qq|
35 </tr>
36 |;
37
38 my $programs;
39
40 sub hh { substr $_[0], 8, 2 }
41 sub mm { substr $_[0], 10, 2 }
42
43 sub in_mins { hh($_[0]) * 60 + mm($_[0]) }
44
45 foreach my $p ( @{ $tv->{programme} } ) {
46 warn "# p ",dump $p;
47 my $t_start = in_mins $p->{start};
48 my $t_stop = in_mins $p->{stop};
49
50 warn "# t $t_start - $t_stop\n";
51 if ( ! defined $programs->{ $p->{channel} } ) {
52 push @{ $programs->{ $p->{channel} } }, [ 0, $t_start ];
53 }
54 push @{ $programs->{ $p->{channel} } }, [ $t_start, $t_stop - $t_start, $p ];
55 }
56
57 warn "# programs ", dump $programs;
58
59 foreach my $hh ( 0 .. 23 ) {
60 foreach my $mm ( 0 .. 59 ) {
61
62 my $hhmm = sprintf '%02d:%02d', $hh, $mm;
63
64 print "<!-- $hh$mm -->\n";
65
66 my @td;
67
68 foreach my $c ( @channels ) {
69 if ( $programs->{$c}->[0]->[0] == $hh * 60 + $mm ) {
70 my $p = shift @{ $programs->{$c} };
71 my $span = $p->[1] - 1;
72 push @td, join(''
73 , qq|<td rowspan=$span>|
74 , join("\n"
75 , qq|<span class="hhmm">$hhmm</span>|
76 , $p->[2]->{title}->{content} || '-'
77 , "<!-- $c -->"
78 )
79 . qq|</td>|
80 );
81 }
82 }
83
84 my ($th,$class) = ('','');
85 ($th,$class) = ( "<th rowspan=60>$hh</th>", ' class="hour"' ) if $mm == 0;
86 print qq|<tr$class>$th|, join('', @td), qq|</tr>\n|;
87 }
88 }
89
90 print qq|
91 </table>
92 |;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26