Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Sep 20, 2024
1 parent cdfbd0e commit e3f3fa4
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions objects/aVideoEncoder.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}
$obj = new stdClass();
$obj->error = true;
$obj->lines = array();

global $global, $config;
if (!isset($global['systemRootPath'])) {
Expand All @@ -27,8 +28,8 @@
$global['bypassSameDomainCheck'] = 1;
if (empty($_REQUEST)) {
$obj->msg = ("Your POST data is empty, maybe your video file is too big for the host");
$obj->SERVER_ADDR = $_SERVER['SERVER_ADDR'];
$obj->dir = __DIR__;
//$obj->SERVER_ADDR = $_SERVER['SERVER_ADDR'];
//$obj->dir = __DIR__;
_error_log($obj->msg);
die(json_encode($obj));
}
Expand Down Expand Up @@ -66,31 +67,39 @@
// check if there is en video id if yes update if is not create a new one
$video = new Video("", "", @$_REQUEST['videos_id'], true);

if (!empty($video->getId()) && !empty($_REQUEST['first_request']) && !empty($_REQUEST['downloadURL'])) {
if (!empty($video->getId()) && !empty($_REQUEST['first_request']) && !empty($_REQUEST['downloadURL'])) {
$obj->lines[] = __LINE__;
_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->lines[] = __LINE__;
$obj->video_id = @$_REQUEST['videos_id'];
$title = $video->getTitle();
$description = $video->getDescription();
if (empty($title) && !empty($_REQUEST['title'])) {
$obj->lines[] = __LINE__;
_error_log("aVideoEncoder.json: Title updated {$_REQUEST['title']} ");
$title = $video->setTitle($_REQUEST['title']);
} elseif (empty($title)) {
$obj->lines[] = __LINE__;
$video->setTitle("Automatic Title");
} else {
$obj->lines[] = __LINE__;
_error_log("aVideoEncoder.json: Title not updated {$_REQUEST['title']} ");
}

if (empty($description)) {
$obj->lines[] = __LINE__;
$video->setDescription($_REQUEST['description']);
}


if (!empty($_REQUEST['duration'])) {
$obj->lines[] = __LINE__;
$duration = $video->getDuration();
if (empty($duration) || $duration === 'EE:EE:EE') {
$obj->lines[] = __LINE__;
$video->setDuration($_REQUEST['duration']);
}
}
Expand All @@ -101,15 +110,18 @@
_error_log("aVideoEncoder.json: Encoder receiving post " . json_encode($_REQUEST));
//_error_log(print_r($_REQUEST, true));
if (preg_match("/(mp3|wav|ogg)$/i", $_REQUEST['format'])) {
$obj->lines[] = __LINE__;
$type = 'audio';
$video->setType($type);
} elseif (preg_match("/(mp4|webm|zip)$/i", $_REQUEST['format'])) {
$obj->lines[] = __LINE__;
$type = 'video';
$video->setType($type);
}

$videoFileName = $video->getFilename();
if (empty($videoFileName)) {
$obj->lines[] = __LINE__;
$paths = Video::getNewVideoFilename();
$filename = $paths['filename'];
$videoFileName = $video->setFilename($videoFileName);
Expand All @@ -119,18 +131,23 @@
$destination_local = "{$paths['path']}{$videoFileName}";

if (!empty($_FILES)) {
$obj->lines[] = __LINE__;
_error_log("aVideoEncoder.json: Files " . json_encode($_FILES));
} else {
$obj->lines[] = __LINE__;
_error_log("aVideoEncoder.json: Files EMPTY");
if (!empty($_REQUEST['downloadURL'])) {
$obj->lines[] = __LINE__;
$_FILES['video']['tmp_name'] = downloadVideoFromDownloadURL($_REQUEST['downloadURL']);
if (empty($_FILES['video']['tmp_name'])) {
$obj->lines[] = __LINE__;
_error_log("aVideoEncoder.json: ******** Download ERROR " . $_REQUEST['downloadURL']);
}
}
}

if (!empty($_FILES['video']['error'])) {
$obj->lines[] = __LINE__;
$phpFileUploadErrors = [
0 => 'There is no error, the file uploaded with success',
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
Expand All @@ -143,64 +160,79 @@
];
_error_log("aVideoEncoder.json: ******** Files ERROR " . $phpFileUploadErrors[$_FILES['video']['error']]);
if (!empty($_REQUEST['downloadURL'])) {
$obj->lines[] = __LINE__;
$_FILES['video']['tmp_name'] = downloadVideoFromDownloadURL($_REQUEST['downloadURL']);
}
}
$_REQUEST['chunkFile'] = str_replace('../', '', $_REQUEST['chunkFile']);
if (empty($_FILES['video']['tmp_name']) && isValidURLOrPath($_REQUEST['chunkFile'])) {
$obj->lines[] = __LINE__;
$_FILES['video']['tmp_name'] = $_REQUEST['chunkFile'];
}

// get video file from encoder
if (!empty($_FILES['video']['tmp_name'])) {
$obj->lines[] = __LINE__;
$resolution = '';
if (!empty($_REQUEST['resolution'])) {
$obj->lines[] = __LINE__;
if (!in_array($_REQUEST['resolution'], $global['avideo_possible_resolutions'])) {
$obj->lines[] = __LINE__;
$msg = "This resolution is not possible {$_REQUEST['resolution']}";
_error_log($msg);
forbiddenPage($msg);
}
$resolution = "_{$_REQUEST['resolution']}";
}
$obj->lines[] = __LINE__;
$filename = "{$videoFileName}{$resolution}.{$_REQUEST['format']}";

$fsize = filesize($_FILES['video']['tmp_name']);

_error_log("aVideoEncoder.json: receiving video upload to {$filename} filesize=" . ($fsize) . " (" . humanFileSize($fsize) . ")" . json_encode($_FILES));
$destinationFile = decideMoveUploadedToVideos($_FILES['video']['tmp_name'], $filename);
} else {
$obj->lines[] = __LINE__;
// set encoding
$video->setStatus(Video::$statusEncoding);
//$video->setAutoStatus(Video::$statusActive);
}
if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination_local}.jpg")) {
$obj->lines[] = __LINE__;
if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$destination_local}.jpg")) {
$obj->lines[] = __LINE__;
$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")) {
$obj->lines[] = __LINE__;
if (!move_uploaded_file($_FILES['gifimage']['tmp_name'], "{$destination_local}.gif")) {
$obj->lines[] = __LINE__;
$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($_REQUEST['encoderURL'])) {
$obj->lines[] = __LINE__;
$video->setEncoderURL($_REQUEST['encoderURL']);
}

if (!empty($_REQUEST['categories_id'])) {
$obj->lines[] = __LINE__;
$video->setCategories_id($_REQUEST['categories_id']);
}
$video_id = $video->save();
$video->updateDurationIfNeed();
$video->updateHLSDurationIfNeed();

if (!empty($_REQUEST['usergroups_id'])) {
$obj->lines[] = __LINE__;
if (!is_array($_REQUEST['usergroups_id'])) {
$obj->lines[] = __LINE__;
$_REQUEST['usergroups_id'] = [$_REQUEST['usergroups_id']];
}
UserGroups::updateVideoGroups($video_id, $_REQUEST['usergroups_id']);
Expand All @@ -213,12 +245,16 @@
$obj->video_id_hash = $v->getVideoIdHash();
$obj->releaseDate = @$_REQUEST['releaseDate'];
$obj->releaseTime = @$_REQUEST['releaseTime'];
$obj->lines[] = __LINE__;

_error_log("aVideoEncoder.json: Files Received for video {$video_id}: " . $video->getTitle());
if (!empty($destinationFile)) {
$obj->lines[] = __LINE__;
if (file_exists($destinationFile)) {
$obj->lines[] = __LINE__;
_error_log("aVideoEncoder.json: Success $destinationFile ");
} else {
$obj->lines[] = __LINE__;
_error_log("aVideoEncoder.json: ERROR $destinationFile ");
}
}
Expand Down

0 comments on commit e3f3fa4

Please sign in to comment.