diff --git a/objects/aVideoEncoder.json.php b/objects/aVideoEncoder.json.php index a9a80fdbe..c6877e434 100644 --- a/objects/aVideoEncoder.json.php +++ b/objects/aVideoEncoder.json.php @@ -1,212 +1,212 @@ error = true; global $global, $config; if (!isset($global['systemRootPath'])) { require_once '../videos/configuration.php'; } if (empty($_POST)) { $obj->msg = __("Your POST data is empty, maybe your video file is too big for the host"); _error_log($obj->msg); die(json_encode($obj)); } _error_log("aVideoEncoder.json: start"); if (empty($_POST['format']) || !in_array($_POST['format'], $global['allowedExtension'])) { _error_log("aVideoEncoder.json: Extension not allowed File " . __FILE__ . ": " . json_encode($_POST)); die(); } if(!isset($_REQUEST['encodedPass'])){ $_REQUEST['encodedPass'] = 1; } useVideoHashOrLogin(); if (!User::canUpload()) { _error_log("aVideoEncoder.json: Permission denied to receive a file: " . json_encode($_POST)); $obj->msg = __("Permission denied to receive a file: ") . json_encode($_POST); _error_log($obj->msg); die(json_encode($obj)); } if (!empty($_POST['videos_id']) && !Video::canEdit($_POST['videos_id'])) { _error_log("aVideoEncoder.json: Permission denied to edit a video: " . json_encode($_POST)); $obj->msg = __("Permission denied to edit a video: ") . json_encode($_POST); _error_log($obj->msg); die(json_encode($obj)); } _error_log("aVideoEncoder.json: start to receive: " . json_encode($_POST)); // check if there is en video id if yes update if is not create a new one $video = new Video("", "", @$_POST['videos_id']); if(!empty($video->getId()) && !empty($_REQUEST['first_request'])){ _error_log("aVideoEncoder.json: There is a new video to replace the existing one, we will delete the current files videos_id = ".$video->getId()); $video->removeVideoFiles(); } $obj->video_id = @$_POST['videos_id']; $title = $video->getTitle(); $description = $video->getDescription(); if (empty($title) && !empty($_POST['title'])) { $title = $video->setTitle($_POST['title']); } elseif (empty($title)) { $video->setTitle("Automatic Title"); } if (empty($description)) { $video->setDescription($_POST['description']); } if(!empty($_REQUEST['duration'])){ $duration = $video->getDuration(); if(empty($duration) || $duration === 'EE:EE:EE'){ $video->setDuration($_REQUEST['duration']); } } $status = $video->setAutoStatus(); $video->setVideoDownloadedLink($_POST['videoDownloadedLink']); _error_log("aVideoEncoder.json: Encoder receiving post " . json_encode($_POST)); //_error_log(print_r($_POST, true)); if (preg_match("/(mp3|wav|ogg)$/i", $_POST['format'])) { $type = 'audio'; $video->setType($type); } elseif (preg_match("/(mp4|webm|zip)$/i", $_POST['format'])) { $type = 'video'; $video->setType($type); } $videoFileName = $video->getFilename(); if (empty($videoFileName)) { $paths = Video::getNewVideoFilename(); $filename = $paths['filename']; $videoFileName = $video->setFilename($videoFileName); } -$paths = Video::getPaths($videoFilename); +$paths = Video::getPaths($videoFilename, true); $destination_local = "{$paths['path']}{$videoFileName}"; if (!empty($_FILES)) { _error_log("aVideoEncoder.json: Files " . json_encode($_FILES)); } else { _error_log("aVideoEncoder.json: Files EMPTY"); if (!empty($_REQUEST['downloadURL'])) { $_FILES['video']['tmp_name'] = downloadVideoFromDownloadURL($_REQUEST['downloadURL']); if (empty($_FILES['video']['tmp_name'])) { _error_log("aVideoEncoder.json: ******** Download ERROR " . $_REQUEST['downloadURL']); } } } if (!empty($_FILES['video']['error'])) { $phpFileUploadErrors = array( 0 => 'There is no error, the file uploaded with success', 1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 3 => 'The uploaded file was only partially uploaded', 4 => 'No file was uploaded', 6 => 'Missing a temporary folder', 7 => 'Failed to write file to disk.', 8 => 'A PHP extension stopped the file upload.', ); _error_log("aVideoEncoder.json: ******** Files ERROR " . $phpFileUploadErrors[$_FILES['video']['error']]); if (!empty($_POST['downloadURL'])) { $_FILES['video']['tmp_name'] = downloadVideoFromDownloadURL($_POST['downloadURL']); } } if (empty($_FILES['video']['tmp_name']) && !empty($_POST['chunkFile'])) { $_FILES['video']['tmp_name'] = $_POST['chunkFile']; } // get video file from encoder if (!empty($_FILES['video']['tmp_name'])) { $resolution = ""; if (!empty($_POST['resolution'])) { $resolution = "_{$_POST['resolution']}"; } $filename = "{$videoFileName}{$resolution}.{$_POST['format']}"; $fsize = filesize($_FILES['video']['tmp_name']); _error_log("aVideoEncoder.json: receiving video upload to {$filename} filesize=" . ($fsize) . " (" . humanFileSize($fsize) . ")" . json_encode($_FILES)); decideMoveUploadedToVideos($_FILES['video']['tmp_name'], $filename); } else { // set encoding $video->setStatus(Video::$statusEncoding); } if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination_local}.jpg")) { if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$destination_local}.jpg")) { $obj->msg = print_r(sprintf(__("Could not move image file [%s.jpg]"), $destination_local), true); _error_log("aVideoEncoder.json: " . $obj->msg); die(json_encode($obj)); } } if (!empty($_FILES['gifimage']['tmp_name']) && !file_exists("{$destination_local}.gif")) { if (!move_uploaded_file($_FILES['gifimage']['tmp_name'], "{$destination_local}.gif")) { $obj->msg = print_r(sprintf(__("Could not move gif image file [%s.gif]"), $destination_local), true); _error_log("aVideoEncoder.json: " . $obj->msg); die(json_encode($obj)); } } if (!empty($_POST['encoderURL'])) { $video->setEncoderURL($_POST['encoderURL']); } if (!empty($_POST['categories_id'])) { $video->setCategories_id($_POST['categories_id']); } $video_id = $video->save(); $video->updateDurationIfNeed(); $video->updateHLSDurationIfNeed(); if (!empty($_POST['usergroups_id'])) { if (!is_array($_POST['usergroups_id'])) { $_POST['usergroups_id'] = array($_POST['usergroups_id']); } UserGroups::updateVideoGroups($video_id, $_POST['usergroups_id']); } $obj->error = false; $obj->video_id = $video_id; $v = new Video('', '', $video_id); $obj->video_id_hash = $v->getVideoIdHash(); _error_log("aVideoEncoder.json: Files Received for video {$video_id}: " . $video->getTitle()); die(json_encode($obj)); /* _error_log(print_r($_POST, true)); _error_log(print_r($_FILES, true)); var_dump($_POST, $_FILES); */ function downloadVideoFromDownloadURL($downloadURL) { global $global; _error_log("aVideoEncoder.json: Try to download " . $downloadURL); $file = url_get_contents($_POST['downloadURL']); if (strlen($file)<20000) { //it is not a video return false; } _error_log("aVideoEncoder.json: Got the download " . $downloadURL); if ($file) { $_FILES['video']['name'] = basename($downloadURL); $temp = Video::getStoragePath()."cache/tmpFile/" . $_FILES['video']['name']; _error_log("aVideoEncoder.json: save " . $temp); make_path($temp); file_put_contents($temp, $file); return $temp; } return false; } diff --git a/objects/aVideoEncoderReceiveImage.json.php b/objects/aVideoEncoderReceiveImage.json.php index 85bd73b98..8489c32b8 100644 --- a/objects/aVideoEncoderReceiveImage.json.php +++ b/objects/aVideoEncoderReceiveImage.json.php @@ -1,148 +1,148 @@ error = true; global $global, $config; if(!isset($global['systemRootPath'])){ require_once '../videos/configuration.php'; } if (empty($_POST)) { $obj->msg = __("Your POST data is empty, maybe your video file is too big for the host"); _error_log("ReceiveImage: ".$obj->msg); die(json_encode($obj)); } useVideoHashOrLogin(); if (!User::canUpload()) { $obj->msg = __("Permission denied to receive a file: " . json_encode($_POST)); _error_log("ReceiveImage: ".$obj->msg); die(json_encode($obj)); } if(!Video::canEdit($_POST['videos_id'])){ $obj->msg = __("Permission denied to edit a video: " . json_encode($_POST)); _error_log("ReceiveImage: ".$obj->msg); die(json_encode($obj)); } _error_log("ReceiveImage: Start receiving image ". json_encode($_FILES)."". json_encode($_POST)); // check if there is en video id if yes update if is not create a new one $video = new Video("", "", $_POST['videos_id']); $obj->video_id = $_POST['videos_id']; $videoFileName = $video->getFilename(); -$paths = Video::getPaths($videoFileName); +$paths = Video::getPaths($videoFileName, true); $destination_local = "{$paths['path']}{$videoFileName}"; _error_log("ReceiveImage: videoFilename = [$videoFileName] destination_local = {$destination_local} Encoder receiving post ". json_encode($_FILES)); $obj->jpgDest = "{$destination_local}.jpg"; if (!empty($_FILES['image']['tmp_name']) && ( !empty($_REQUEST['update_video_id']) || !file_exists($obj->jpgDest) || filesize($obj->jpgDest)===42342)) { if (!move_uploaded_file($_FILES['image']['tmp_name'], $obj->jpgDest)) { $obj->msg = print_r(sprintf(__("Could not move image file [%s.jpg]"), $destination_local), true); _error_log("ReceiveImage: ".$obj->msg); die(json_encode($obj)); } else{ $obj->jpgDestSize = humanFileSize(filesize($obj->jpgDest)); } }else{ if(empty($_FILES['image']['tmp_name'])){ _error_log("ReceiveImage: empty \$_FILES['image']['tmp_name'] " . json_encode($_FILES)); } if(file_exists($obj->jpgDest)){ _error_log("ReceiveImage: File already exists ".$obj->jpgDest); if(filesize($obj->jpgDest)!==42342){ _error_log("ReceiveImage: file is not an error image ".filesize($obj->jpgDest)); } } } if(!empty($_FILES['spectrumimage']['tmp_name'])){ $obj->jpgSpectrumDest = "{$destination_local}_spectrum.jpg"; if ((!empty($_REQUEST['update_video_id']) || !file_exists($obj->jpgSpectrumDest) || filesize($obj->jpgSpectrumDest)===42342)) { if (!move_uploaded_file($_FILES['spectrumimage']['tmp_name'], $obj->jpgSpectrumDest)) { $obj->msg = print_r(sprintf(__("Could not move image file [%s.jpg]"), $destination_local), true); _error_log("ReceiveImage: ".$obj->msg); die(json_encode($obj)); } else{ $obj->jpgSpectrumDest = humanFileSize(filesize($obj->jpgSpectrumDest)); } }else{ if(empty($_FILES['spectrumimage']['tmp_name'])){ _error_log("ReceiveImage: empty \$_FILES['spectrumimage']['tmp_name'] " . json_encode($_FILES)); } if(file_exists($obj->jpgSpectrumDest)){ _error_log("ReceiveImage: File already exists ".$obj->jpgDest); if(filesize($obj->jpgSpectrumDest)!==42342){ _error_log("ReceiveImage: file is not an error image ".filesize($obj->jpgDest)); } } } } $obj->gifDest = "{$destination_local}.gif"; if (!empty($_FILES['gifimage']['tmp_name']) && (!empty($_REQUEST['update_video_id']) || !file_exists($obj->gifDest) || filesize($obj->gifDest)===2095341)) { if (!move_uploaded_file($_FILES['gifimage']['tmp_name'], $obj->gifDest)) { $obj->msg = print_r(sprintf(__("Could not move gif image file [%s.gif]"), $destination_local), true); _error_log("ReceiveImage: ".$obj->msg); die(json_encode($obj)); } else{ $obj->gifDestSize = humanFileSize(filesize($obj->gifDest)); } }else{ if(empty($_FILES['gifimage']['tmp_name'])){ _error_log("ReceiveImage: empty \$_FILES['gifimage']['tmp_name'] " . json_encode($_FILES)); } if(file_exists($obj->gifDest)){ _error_log("ReceiveImage: File already exists ".$obj->gifDest); if(filesize($obj->gifDest)!==42342){ _error_log("ReceiveImage: file is not an error image ".filesize($obj->gifDest)); } } } $obj->webpDest = "{$destination_local}.webp"; if (!empty($_FILES['webpimage']['tmp_name']) && (!empty($_REQUEST['update_video_id']) || !file_exists($obj->webpDest) || filesize($obj->webpDest)===2095341)) { if (!move_uploaded_file($_FILES['webpimage']['tmp_name'], $obj->webpDest)) { $obj->msg = print_r(sprintf(__("Could not move webp image file [%s.webp]"), $destination_local), true); _error_log("ReceiveImage: ".$obj->msg); die(json_encode($obj)); } else{ $obj->webpDestSize = humanFileSize(filesize($obj->webpDest)); } }else{ if(empty($_FILES['webpimage']['tmp_name'])){ _error_log("ReceiveImage: empty \$_FILES['webpimage']['tmp_name'] " . json_encode($_FILES)); } if(file_exists($obj->webpDest)){ _error_log("ReceiveImage: File already exists ".$obj->webpDest); if(filesize($obj->webpDest)!==42342){ _error_log("ReceiveImage: file is not an error image ".filesize($obj->webpDest)); } } } if(!empty($_REQUEST['duration'])){ $duration = $video->getDuration(); if(empty($duration) || $duration === 'EE:EE:EE'){ $video->setDuration($_REQUEST['duration']); } } $videos_id = $video->save(); Video::clearCache($videos_id); Video::updateFilesize($videos_id); $obj->error = false; $obj->video_id = $videos_id; $json = json_encode($obj); _error_log("ReceiveImage: Files Received for video {$videos_id}: " . $video->getTitle()." {$json}"); die($json); /* _error_log(json_encode($_POST)); _error_log(json_encode($_FILES)); var_dump($_POST, $_FILES); */