Associate .avi_high.mp4 files with their relevant .rtvinfo files.
[recordtv.git] / playonwii / index.php
blobc6b360278ee32de8f226fa683b41c8fbf8d9429a
1 <?php
3 include_once( "functions.php" );
5 $extra_path = sanitise_filename( $_GET["path"] );
6 $excluded_preprepare = explode( ":", $_GET["exclude"] );
8 $excluded = array();
10 foreach( $excluded_preprepare as $ex )
12 $excluded[] = sanitise_filename( $ex );
15 $full_videos_dir = $videos_dir;
17 if( $extra_path )
19 $full_videos_dir .= "/$extra_path";
20 $extra_path .= "/";
22 else
24 $extra_path = "";
27 function is_video_dir( $full_path )
29 if( substr_compare( $full_path, "/.", -2 ) == 0 or
30 substr_compare( $full_path, "/..", -3 ) == 0 or
31 substr_compare( $full_path, "/deleted", -8 ) == 0 or
32 substr_compare( $full_path, "/tvguide", -8 ) == 0 )
34 return false;
37 return is_dir( $full_path );
40 function is_not_excluded( $filename )
42 global $excluded;
44 return !in_array( $filename, $excluded );
47 function get_filenames_recursive( &$filenames, $top_dir, $sub_dir = "" )
49 $handle = opendir( "$top_dir/$sub_dir" );
50 if( $handle )
52 while( ( $filename = readdir( $handle ) ) )
54 if( strlen( $sub_dir ) > 0 )
56 $filepath = "$sub_dir/$filename";
58 else
60 $filepath = $filename;
62 if( is_not_excluded( $filename ) &&
63 is_video_dir( "$top_dir/$sub_dir/$filename" ) )
65 get_filenames_recursive( $filenames, $top_dir, $filepath );
67 else
69 $filenames[$filepath] = '';
72 closedir($handle);
76 function pretty_date( $date )
78 global $num_to_month;
80 $tm = mktime(
81 (int)( substr( $date, 11, 2 ) ),
82 (int)( substr( $date, 14, 2 ) ),
84 (int)( substr( $date, 5, 2 ) ),
85 (int)( substr( $date, 8, 2 ) ),
86 (int)( substr( $date, 0, 4 ) ) );
88 return date( "D d M, H:i", $tm );
91 function single_quote_attribute_escape( $value )
93 return str_replace( "'", "&apos;", $value );
96 function get_info_from_file( $fn )
98 $title = "";
99 $sub_title = "";
100 $description = "";
101 $date = "";
102 $channel = "";
104 $handle = fopen( $fn, "r" );
106 if( $handle )
108 while ( !feof( $handle ) )
110 $line = fgets( $handle );
111 $line = substr( $line, 0, -1 );
113 list( $k, $v ) = split( "=", $line, 2 );
115 switch( $k )
117 case "title":
119 $title = $v;
120 break;
122 case "sub_title":
124 $sub_title = $v;
125 break;
127 case "description":
129 $description = $v;
130 break;
132 case "startTime":
134 $date = $v;
135 break;
137 case "channel_pretty":
139 $channel = $v;
140 break;
145 fclose( $handle );
148 return array( $title, $date, $channel, $sub_title, $description );
151 function get_info_from_filename( $fn )
153 if( preg_match( '/^(.*?)-(.*)\\..*$/', $fn, $matches ) )
155 $title = $matches[1];
156 $date = $matches[2];
158 else
160 $title = substr( $fn, 0, strlen( $fn ) - 4 );
161 $date = "";
164 return array( $title, $date );
167 function get_info( $filename, $filenames )
169 global $full_videos_dir;
171 $title = Null;
173 if( preg_match( '/^(.*?)\\.(flv|avi|avi_high\\.mp4|webm|mp4)$/', $filename, $matches ) )
176 $infofn = $matches[1] . ".rtvinfo";
178 if( array_key_exists( $infofn, $filenames ) )
180 list( $title, $date, $channel, $sub_title, $description ) =
181 get_info_from_file( $full_videos_dir . "/" . $infofn );
183 else
185 list( $title, $date ) = get_info_from_filename( $filename );
186 $channel = "";
187 $sub_title = "";
188 $description = "";
190 $titles[$title][] = array( $num, $date, $channel, $sub_title,
191 $description );
192 $num++;
195 return array( $title, $date, $channel, $sub_title, $description );
198 // This is a hash filename -> nothing of all files in the videos directory
199 // and subdirectories
200 $filenames = array();
201 get_filenames_recursive( $filenames, $full_videos_dir );
203 // This is a hash filename -> nothing of all files in the deleted directory
204 $deleted_filenames = array();
205 $handle = opendir( $deleted_dir );
206 if( $handle )
208 while( ( $filename = readdir( $handle ) ) )
210 $deleted_filenames[$filename] = '';
213 closedir($handle);
217 // This is a hash title->array( array( filenumber, date, filename, channel ) )
218 $titles = array();
219 $num = 0;
221 $nondeleted_filenames = array();
223 foreach ( $filenames as $fn => $blank )
225 $modified_fn = str_replace( "/", "_", "$extra_path$fn" );
226 if( !array_key_exists( $modified_fn, $deleted_filenames ) )
228 $nondeleted_filenames[$fn] = '';
231 #array_diff_key( $filenames, $deleted_filenames );
233 $sorted_fns = array_keys( $nondeleted_filenames );
234 sort( $sorted_fns );
236 foreach( $sorted_fns as $filename )
238 list( $title, $date, $channel, $sub_title, $description ) = get_info(
239 $filename, $nondeleted_filenames );
241 if( $title != Null )
243 $titles[$title][] = array( $num, $date, $channel, $sub_title,
244 $description, $filename );
245 $num++;
251 <html>
253 <head>
254 <title>Recorded programmes</title>
255 <style type="text/css">
256 body {
257 font-family: verdana, sans-serif;
258 text-align: center;
261 text-decoration: none;
262 color: black;
264 a:hover {
265 color: red;
267 a.deletelink {
268 color:red;
269 font-size: xx-small;
271 a.title {
272 color: blue;
274 span.smalltime {
275 font-size: smaller;
276 color: gray;
278 span.smalltime:hover {
279 color: red;
281 h2 {
282 font-size: x-large;
283 font-weight: normal;
284 color: blue;
285 margin: 2px;
287 td.dates {
288 font-size: small;
290 </style>
291 <script language="JavaScript">
293 function makeRequest( url, arg )
295 var httpRequest;
297 if( window.XMLHttpRequest ) // Mozilla, Safari etc.
299 httpRequest = new XMLHttpRequest();
301 else if( window.ActiveXObject ) // IE
305 httpRequest = new ActiveXObject( "Msxml2.XMLHTTP" );
307 catch( e )
311 httpRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
313 catch( e )
319 if( !httpRequest )
321 return false;
324 httpRequest.onreadystatechange = function()
326 receiveAnswer( httpRequest, arg );
329 httpRequest.open('GET', url, true);
330 httpRequest.send('');
333 function receiveAnswer( httpRequest, prog_filename )
335 if( httpRequest.readyState == 4 )
337 if( httpRequest.status != 200 )
339 document.location = "delete_error.php?filename=" + prog_filename
345 function mouse_over( tr_id )
347 tr_el = document.getElementById( tr_id );
348 tr_el.style.backgroundColor = '#ffaaaa';
351 function mouse_out( tr_id )
353 tr_el = document.getElementById( tr_id );
354 tr_el.style.backgroundColor = 'transparent';
357 function title_click( table_id )
359 table_el = document.getElementById( table_id );
360 if( table_el.style.display == 'inline' )
362 table_el.style.display = 'none';
364 else
366 table_el.style.display = 'inline';
371 function delete_prog( prog_filename )
373 makeRequest( 'delete.php?filename=' + prog_filename,
374 prog_filename );
375 tr_el = document.getElementById( 'tr_' + prog_filename );
376 tr_el.style.display = 'none';
379 </script>
380 </head>
382 <body>
383 <h1>Recorded programmes</h1>
385 <center>
386 <?php
387 ksort( $titles );
388 $table_counter = 0;
389 foreach( $titles as $title => $arr )
391 list( $num, $date, $channel, $sub_title ) = $arr[0];
392 print "<h2><a class='title' href='javascript: title_click( \"table_$table_counter\" )'>$title</a></h2>\n";
394 print "<table id='table_$table_counter' style='display: none' width='90%' cellpadding='0' cellspacing='0' border='0'>";
395 foreach( $arr as $lst )
397 list( $num, $date, $channel, $sub_title, $description,
398 $filename ) = $lst;
400 $dotpos = strrpos( $filename, '.' );
401 $ext = substr( $filename, $dotpos );
402 $play_url = "$videos_uri/$extra_dir$filename";
403 if( $ext == ".webm" || $ext == ".mp4" )
405 $play_url = "play-html5.php?filename=$extra_path$filename";
407 else if( $ext == ".flv" )
409 $play_url = "play.php?filename=$extra_path$filename";
412 print "<tr id='tr_$extra_path$filename'><td><a href='$play_url' style='padding-right: 10px'";
414 print " title='".single_quote_attribute_escape( $description )
415 ."'";
417 print ">";
419 if( $sub_title )
421 print $sub_title . " <span class='smalltime'>(";
424 print pretty_date( $date );
426 if( $channel )
428 print " on $channel";
431 if( $sub_title )
433 print ")</span>";
436 print "</a></td>";
437 print "<td><a class='deletelink' onmouseover='mouse_over(\"tr_$extra_path$filename\")' onmouseout='mouse_out(\"tr_$extra_path$filename\")' href='javascript: delete_prog( \"$extra_path$filename\" )'>[DELETE]</a></td></tr>\n";
439 print "</table>\n";
440 $table_counter += 1;
443 </center>
445 </body>
447 </html>