File indexing completed on 2024-06-23 05:51:18
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Backend_Commands_ConvertVideo implements Local_Queue_CommandInterface 0024 { 0025 0026 protected $collectionId; 0027 protected $fileId; 0028 protected $fileType; 0029 0030 public static $VIDEO_FILE_TYPES = array('video/3gpp','video/3gpp2','video/mpeg','video/quicktime','video/x-flv','video/webm','application/ogg','video/x-ms-asf','video/x-matroska', 'video/mp4'); 0031 0032 /** 0033 * PHP 5 allows developers to declare constructor methods for classes. 0034 * Classes which have a constructor method call this method on each newly-created object, 0035 * so it is suitable for any initialization that the object may need before it is used. 0036 * 0037 * Note: Parent constructors are not called implicitly if the child class defines a constructor. 0038 * In order to run a parent constructor, a call to parent::__construct() within the child constructor is required. 0039 * 0040 * param [ mixed $args [, $... ]] 0041 * 0042 * @param int $collectionId 0043 * @param int $fileId 0044 * 0045 * @link http://php.net/manual/en/language.oop5.decon.php 0046 */ 0047 public function __construct($collectionId, $fileId, $fileType) 0048 { 0049 $this->collectionId = $collectionId; 0050 $this->fileId = $fileId; 0051 $this->fileType = $fileType; 0052 0053 } 0054 0055 public function doCommand() 0056 { 0057 0058 return $this->callConvertVideo($this->collectionId, $this->fileId, $this->fileType); 0059 } 0060 0061 protected function callConvertVideo($collectionId, $fileId, $fileType) 0062 { 0063 0064 $log = Zend_Registry::get('logger'); 0065 $log->debug('**********' . __CLASS__ . '::' . __FUNCTION__ . '**********' . "\n"); 0066 0067 $videoServer = new Default_Model_DbTable_Video(); 0068 $data = array('id' => $videoServer->getNewId(),'collection_id' => $collectionId,'file_id' => $fileId, 'create_timestamp' => new Zend_Db_Expr('NOW()')); 0069 $videoServer->insert($data); 0070 0071 //call video convert server 0072 $salt = PPLOAD_DOWNLOAD_SECRET; 0073 $timestamp = time() + 3600; // one hour valid 0074 $hash = hash('sha512',$salt . $collectionId . $timestamp); // order isn't important at all... just do the same when verifying 0075 $url = PPLOAD_API_URI . 'files/download/id/' . $fileId . '/s/' . $hash . '/t/' . $timestamp; 0076 $url .= '/lt/filepreview/' . $fileId; 0077 $url = Default_Model_PpLoad::createDownloadUrl($collectionId,$fileId,array('id'=>$fileId, 't'=>$timestamp, 'lt'=>'filepreview')); 0078 0079 $result = $videoServer->storeExternalVideo($collectionId, $fileType, $url); 0080 0081 if(!empty($result) && $result != 'Error') { 0082 //Save Preview URL in DB 0083 $config = Zend_Registry::get('config'); 0084 $cdnurl = $config->videos->media->cdnserver; 0085 $url_preview = $cdnurl.$collectionId."/".$result.".mp4"; 0086 $url_thumb = $cdnurl.$collectionId."/".$result."_thumb.png"; 0087 $data = array('url_preview' => $url_preview, 'url_thumb' => $url_thumb); 0088 $videoServer->update($data, "collection_id = $collectionId AND file_id = $fileId"); 0089 0090 0091 } else { 0092 $log->debug("Error on Converting Video! Result: ".$result); 0093 return false; 0094 } 0095 0096 0097 return true; 0098 } 0099 0100 }