#!/usr/bin/env php format('dmy-Hi'); //Get a tmestamp to put on the logfile. $dbconn = pg_connect("host=$dbhost dbname=$dbname user=$dbuser password=$dbpass options='--client_encoding=UTF8'") //Connect to db. or die('error_dbconnect :Could not connect: ' . pg_last_error($dbconn)); $query = "SELECT id, cuein, cueout, file_exists, length, directory, filepath FROM \"$dbtable\" ORDER BY id"; // Build sql query. $result = pg_query($query) or die('error_qfail :Query failed: ' ."\r\n" . pg_last_error($dbconn)); //Execute the query and store in $result. ob_start(); //Start output buffering while ($track_meta = pg_fetch_array($result, null, PGSQL_ASSOC)) { ob_clean(); // Cleanup anything left over in the output buffer from the last loop. if ($track_meta['file_exists'] == 't'){ //Check file actually exists, discard ones that don't $file_location = $track_meta['directory'] . $track_meta['filepath']; // Get info from results. $id = $track_meta['id']; // Get info from results. $real_length_time = strtotime("1/1/1970 " . $track_meta['length'] . " GMT"); // Get info from results. $calculated_length = $real_length_time; $file_location = $track_meta['directory'] . $track_meta['filepath']; // Get info from results. $id = $track_meta['id']; $real_length_time = strtotime("1/1/1970 " . $track_meta['length'] . " GMT"); // Get info from results. $calculated_length = $real_length_time; // Calculate info from results. if (! isset($track_meta['cuein'])){ //Check quein is available. echo "Missing cuein: $id : $file_location \r\n"; } else { $cuein = strtotime("1/1/1970 " . $track_meta['cuein']. " GMT"); $calculated_length = $calculated_length - $cuein; } if (! isset($track_meta['cueout'])){ echo "Missing cueout: $id : $file_location \r\n"; } else { $cueout = strtotime("1/1/1970 " . $track_meta['cueout'] . " GMT"); $calculated_length = $calculated_length - ($real_length_time - $cueout); } if (! isset($track_meta['cuein'])){ //Check quein is available. echo "Missing cuein: $id : $file_location \r\n"; } else { $cuein = strtotime("1/1/1970 " . $track_meta['cuein']. " GMT"); $calculated_length = $calculated_length - $cuein; } if (! isset($track_meta['cueout'])){ echo "Missing cueout: $id : $file_location \r\n"; } else { $cueout = strtotime("1/1/1970 " . $track_meta['cueout'] . " GMT"); $calculated_length = $calculated_length - ($real_length_time - $cueout); } if ($real_length_time > $calculated_length + $maxlengthdif) { exec ("touch \"$file_location\""); //for some reason php's touch() function doesn't triger airtime's import so exec a shell command echo "Fixing: $id : $real_length_time : $cuein : $cueout : $calculated_length: $file_location \r\n"; } elseif ($real_length_time == $calculated_length) { echo "Length equal: $id : $real_length_time : $cuein : $cueout : $calculated_length: $file_location \r\n"; } elseif ($calculated_length < 0) { echo "Bad queout: $id : $real_length_time : $cuein : $cueout : $calculated_length: $file_location \r\n"; exec ("touch \"$file_location\""); //for some reason php's touch() function doesn't triger airtime's import so exec a shell command } else{ echo "Length OK: $id : $real_length_time : $cuein : $cueout : $calculated_length: $file_location \r\n"; } } file_put_contents("/tmp/fix-radio-lenghts-log-$lfts", ob_get_contents(),FILE_APPEND); ob_flush(); } ?>