Added some new channels.
[recordtv.git] / playonwii / index.php
blobac5397fdd478b93c053b953a470a248fc18c0275
1 <?php
3 include_once( "functions.php" );
5 function pretty_date( $date )
7 global $num_to_month;
9 $tm = mktime(
10 (int)( substr( $date, 11, 2 ) ),
11 (int)( substr( $date, 14, 2 ) ),
13 (int)( substr( $date, 5, 2 ) ),
14 (int)( substr( $date, 8, 2 ) ),
15 (int)( substr( $date, 0, 4 ) ) );
17 return date( "D d M, H:i", $tm );
20 function get_info_from_file( $fn )
22 $title = "";
23 $sub_title = "";
24 $description = "";
25 $date = "";
26 $channel = "";
28 $handle = fopen( $fn, "r" );
30 if( $handle )
32 while ( !feof( $handle ) )
34 $line = fgets( $handle );
35 $line = substr( $line, 0, -1 );
37 list( $k, $v ) = split( "=", $line, 2 );
39 switch( $k )
41 case "title":
43 $title = $v;
44 break;
46 case "sub_title":
48 $sub_title = $v;
49 break;
51 case "description":
53 $description = $v;
54 break;
56 case "startTime":
58 $date = $v;
59 break;
61 case "channel_pretty":
63 $channel = $v;
64 break;
69 fclose( $handle );
72 return array( $title, $date, $channel, $sub_title, $description );
75 function get_info_from_filename( $fn )
77 if( preg_match( '/^(.*?)-(.*)\\..*$/', $fn, $matches ) )
79 $title = $matches[1];
80 $date = $matches[2];
82 else
84 $title = substr( $fn, 0, strlen( $fn ) - 4 );
85 $date = "";
88 return array( $title, $date );
91 function get_info( $filename, $filenames )
93 global $videos_dir;
95 $title = Null;
97 if( preg_match( '/^(.*)\\.flv$/', $filename, $matches ) )
100 $infofn = $matches[1] . ".rtvinfo";
102 if( array_key_exists( $infofn, $filenames ) )
104 list( $title, $date, $channel, $sub_title, $description ) =
105 get_info_from_file( $videos_dir . "/" . $infofn );
107 else
109 list( $title, $date ) = get_info_from_filename( $filename );
110 $channel = "";
111 $sub_title = "";
112 $description = "";
114 $titles[$title][] = array( $num, $date, $channel, $sub_title,
115 $description );
116 $num++;
119 return array( $title, $date, $channel, $sub_title, $description );
122 // This is a hash filename -> nothing of all files in the directory
123 $filenames = array();
124 $handle = opendir( $videos_dir );
125 if( $handle )
127 while( ( $filename = readdir( $handle ) ) )
129 $filenames[$filename] = '';
132 closedir($handle);
135 // This is a hash title->array( array( filenumber, date, filename, channel ) )
136 $titles = array();
137 $num = 0;
139 $sorted_fns = array_keys( $filenames );
140 rsort( $sorted_fns );
142 foreach( $sorted_fns as $filename )
144 list( $title, $date, $channel, $sub_title, $description ) = get_info(
145 $filename, $filenames );
147 if( $title != Null )
149 $titles[$title][] = array( $num, $date, $channel, $sub_title,
150 $description, $filename );
151 $num++;
157 <html>
159 <head>
160 <title>Recorded programmes</title>
161 <style type="text/css">
162 body {
163 font-family: verdana, sans-serif;
164 text-align: center;
167 text-decoration: none;
168 color: black;
170 a:hover {
171 color: red;
173 span.smalltime {
174 font-size: smaller;
175 color: gray;
177 span.smalltime:hover {
178 color: red;
180 th {
181 font-size: x-large;
182 font-weight: normal;
183 color: blue;
185 td.dates {
186 font-size: small;
188 </style>
189 </head>
191 <body>
192 <h1>Recorded programmes</h1>
194 <center>
195 <?php
196 print "<table cellpadding='2'>\n";
197 ksort( $titles );
198 foreach( $titles as $title => $arr )
200 list( $num, $date, $channel, $sub_title ) = $arr[0];
201 print "<tr><th style='border-style: solid none none none; border-width: 1px; border-color: black;' width='50%' align='right' valign='top'>$title</th><td width='50%' class='dates'>";
203 foreach( $arr as $lst )
205 list( $num, $date, $channel, $sub_title, $description,
206 $filename ) = $lst;
207 print "<a href='play.php?filename=$filename'";
209 print " title='$description'";
211 print ">";
213 if( $sub_title )
215 print $sub_title . " <span class='smalltime'>(";
218 print pretty_date( $date );
220 if( $channel )
222 print " on $channel";
225 if( $sub_title )
227 print ")</span>";
230 print "</a><br />";
232 print "</td></tr>\n";
233 print "<tr><th></th><td><br /></td></tr>";
235 print "</table>\n";
237 </center>
239 </body>
241 </html>