/[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

Annotation of /program/xmltv.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Sat Oct 31 14:47:07 2009 UTC (14 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 2004 byte(s)
add some css styles to table

1 dpavlin 18 #!/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 dpavlin 19 <html>
17     <head>
18     <meta charset=utf-8>
19 dpavlin 18
20     <style type="text/css">
21    
22 dpavlin 24 td {
23     font-family:sans-serif;
24     vertical-align: top;
25 dpavlin 25 background: #eee;
26 dpavlin 24 }
27    
28 dpavlin 25 th,odd {
29     background: #eef;
30 dpavlin 18 }
31    
32 dpavlin 25 th.even {
33     background: #fcc;
34     }
35    
36 dpavlin 19 .hhmm {
37     font-size: 50%;
38     color: #888;
39     float: right;
40     }
41    
42 dpavlin 18 </style>
43    
44 dpavlin 19 </head>
45     <body>
46    
47 dpavlin 25 <table>
48 dpavlin 18 <tr><td></td>
49     |;
50    
51     my @channels = keys %{ $tv->{channel} };
52     warn "# channels ",dump @channels;
53    
54     print qq|<th><img src="|, $_->{'icon'}->{'src'}, qq|"><br>|, $_->{'display-name'}->{'content'}, qq|</th>| foreach map { $tv->{channel}->{$_} } @channels;
55    
56     print qq|
57     </tr>
58     |;
59    
60     my $programs;
61    
62     sub hh { substr $_[0], 8, 2 }
63     sub mm { substr $_[0], 10, 2 }
64    
65     sub in_mins { hh($_[0]) * 60 + mm($_[0]) }
66    
67     foreach my $p ( @{ $tv->{programme} } ) {
68     warn "# p ",dump $p;
69     my $t_start = in_mins $p->{start};
70     my $t_stop = in_mins $p->{stop};
71    
72     warn "# t $t_start - $t_stop\n";
73     if ( ! defined $programs->{ $p->{channel} } ) {
74     push @{ $programs->{ $p->{channel} } }, [ 0, $t_start ];
75     }
76     push @{ $programs->{ $p->{channel} } }, [ $t_start, $t_stop - $t_start, $p ];
77     }
78    
79     warn "# programs ", dump $programs;
80    
81     foreach my $hh ( 0 .. 23 ) {
82     foreach my $mm ( 0 .. 59 ) {
83    
84     my $hhmm = sprintf '%02d:%02d', $hh, $mm;
85    
86     print "<!-- $hh$mm -->\n";
87    
88     my @td;
89    
90     foreach my $c ( @channels ) {
91     if ( $programs->{$c}->[0]->[0] == $hh * 60 + $mm ) {
92     my $p = shift @{ $programs->{$c} };
93 dpavlin 19 my $span = $p->[1]; # - 1;
94 dpavlin 20
95     my $html = '';
96     $html = join("\n"
97     , qq|<span class="hhmm">$hhmm<br>$span</span>|
98     , $p->[2]->{title}->{content}
99     , "<!-- $c -->"
100     ) if $p->[2];
101    
102     push @td, qq|<td rowspan=$span>$html</td>|;
103 dpavlin 18 }
104     }
105    
106 dpavlin 25 my $class = $hh % 2 == 0 ? 'even' : 'odd';
107    
108     my $th = '';
109     $th = qq|<th rowspan=60 class=$class>$hh</th>| if $mm == 0;
110    
111     print qq|<tr>$th|, join('', @td), qq|</tr>\n|;
112 dpavlin 18 }
113     }
114    
115     print qq|
116     </table>
117 dpavlin 19
118     </body>
119    
120     </html>
121 dpavlin 18 |;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26