Source of file Transcode_Controller.php
Size: 2,332 Bytes - Last Modified: 2021-12-23T10:04:44+00:00
/var/www/docs.ssmods.com/process/src/code/Transcode_Controller.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | <?php /** * Controller to receive pingbacks from video transcoding jobs */ class Transcode_Controller extends Controller { /** * URL That you can access this from * * @config */ private static $url_segment = "transcode-log"; private static $allowed_actions = array( "index", ); // private static $url_handlers = array( // 'transcode-log/$Action/$ID' => 'index' // ); public function init() { parent::init(); } public static function staticAbsoluteLink($action = null) { return Controller::join_links( //Director::absoluteURL(BASE_URL), Director::absoluteURL(Director::BaseURL()), self::$url_segment, $action ); } /* Example pings/updates (to be processed by index) { "id": 898, "errors": { "output": { "jpg": "unknown_error" } }, "output_urls": { "ogv": "", "webm": "", "mp4": "" } } Or { "id": 898, "errors": { }, "output_urls": { "jpg": [ "ftp://user:pass@restruct.nl:21/test/bird-01.jpg" ], "webm": "ftp://user:pass@restruct.nl:21/test/bird.webm", "mp4": "ftp://user:pass@restruct.nl:21/test/bird.mp4", "ogv": "ftp://user:pass@restruct.nl:21/test/bird.ogv" } } */ public function index(SS_HTTPRequest $request) { if($request->isPOST()){ $update = json_decode($request->getBody()); $joblog = TranscodeJob::get()->filter('JobID', (int) $update->id)->first(); // return if status already is done (some protection) if($joblog->JobStatus!=="started"){ return "Error: job status not started"; } // save full update into log object -- no, may contain passwords etc. -- well, fixed but still... //format_id // load files into appropriate relations $transcodable = $joblog->Transcodable(); $transcodable->loadTranscodedFiles(); if(count(get_object_vars($update->errors))){ $joblog->JobErrorMessage = json_encode($update->errors); $joblog->JobStatus = "error"; } else if ($transcodable->transcodingComplete()) { // set status to done when complete... $joblog->JobErrorMessage = ""; $joblog->JobStatus = "done"; } // write logfile $joblog->write(); } else { // this shouldn't happen return "Well hello there..."; } return "Updated"; } } |