mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
get correct extension
This commit is contained in:
parent
83800e502e
commit
a9c12d6c3a
1 changed files with 179 additions and 176 deletions
|
@ -1,176 +1,179 @@
|
||||||
<?php
|
<?php
|
||||||
//error_reporting(0);
|
//error_reporting(0);
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
if (empty($global['systemRootPath'])) {
|
if (empty($global['systemRootPath'])) {
|
||||||
$global['systemRootPath'] = '../';
|
$global['systemRootPath'] = '../';
|
||||||
}
|
}
|
||||||
require_once $global['systemRootPath'] . 'videos/configuration.php';
|
require_once $global['systemRootPath'] . 'videos/configuration.php';
|
||||||
require_once $global['systemRootPath'] . 'objects/user.php';
|
require_once $global['systemRootPath'] . 'objects/user.php';
|
||||||
if (!User::canUpload()) {
|
if (!User::canUpload()) {
|
||||||
die('{"error":"1 ' . __("Permission denied") . '"}');
|
die('{"error":"1 ' . __("Permission denied") . '"}');
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg = '';
|
$msg = '';
|
||||||
$info = $infoObj = '';
|
$info = $infoObj = '';
|
||||||
require_once 'video.php';
|
require_once 'video.php';
|
||||||
|
|
||||||
if (!empty($_POST['id'])) {
|
if (!empty($_POST['id'])) {
|
||||||
if (!Video::canEdit($_POST['id']) && !Permissions::canModerateVideos()) {
|
if (!Video::canEdit($_POST['id']) && !Permissions::canModerateVideos()) {
|
||||||
die('{"error":"2 ' . __("Permission denied") . '"}');
|
die('{"error":"2 ' . __("Permission denied") . '"}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (!is_writable("{$global['systemRootPath']}vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer")) {
|
if (!is_writable("{$global['systemRootPath']}vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer")) {
|
||||||
die('{"error":"Directory ' . $global['systemRootPath'] . 'vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer not writable, please chmod to 777 "}');
|
die('{"error":"Directory ' . $global['systemRootPath'] . 'vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer not writable, please chmod to 777 "}');
|
||||||
}
|
}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TimeLogStart(__FILE__);
|
TimeLogStart(__FILE__);
|
||||||
|
|
||||||
$obj = new Video($_POST['title'], "", @$_POST['id']);
|
$obj = new Video($_POST['title'], "", @$_POST['id']);
|
||||||
|
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
|
|
||||||
$obj->setClean_Title($_POST['clean_title']);
|
$obj->setClean_Title($_POST['clean_title']);
|
||||||
$audioLinks = ['mp3', 'ogg'];
|
$audioLinks = ['mp3', 'ogg'];
|
||||||
$videoLinks = ['mp4', 'webm', 'm3u8'];
|
$videoLinks = ['mp4', 'webm', 'm3u8'];
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
if (!empty($_POST['videoLink'])) {
|
if (!empty($_POST['videoLink'])) {
|
||||||
//var_dump($config->getEncoderURL()."getLinkInfo/". base64_encode($_POST['videoLink']));exit;
|
//var_dump($config->getEncoderURL()."getLinkInfo/". base64_encode($_POST['videoLink']));exit;
|
||||||
$path_parts = pathinfo($_POST['videoLink']);
|
$path_parts = pathinfo($_POST['videoLink']);
|
||||||
$extension = strtolower(@$path_parts["extension"]);
|
//$extension = strtolower(@$path_parts["extension"]);
|
||||||
if (empty($_POST['id']) && !(in_array($extension, $audioLinks) || in_array($extension, $videoLinks))) {
|
$filebasename = explode('?', $path_parts['basename']);
|
||||||
$getLinkInfo = $config->getEncoderURL() . "getLinkInfo/" . base64_encode($_POST['videoLink']);
|
$extension = pathinfo($filebasename[0], PATHINFO_EXTENSION);
|
||||||
_error_log('videoAddNew: '.$getLinkInfo);
|
//var_dump($path_parts, $extension);exit;
|
||||||
$info = url_get_contents($getLinkInfo, '', 180, true);
|
if (empty($_POST['id']) && !(in_array($extension, $audioLinks) || in_array($extension, $videoLinks))) {
|
||||||
$infoObj = _json_decode($info);
|
$getLinkInfo = $config->getEncoderURL() . "getLinkInfo/" . base64_encode($_POST['videoLink']);
|
||||||
$paths = Video::getNewVideoFilename();
|
_error_log('videoAddNew: '.$getLinkInfo);
|
||||||
$filename = $paths['filename'];
|
$info = url_get_contents($getLinkInfo, '', 180, true);
|
||||||
$filename = $obj->setFilename($filename);
|
$infoObj = _json_decode($info);
|
||||||
if (is_object($infoObj)) {
|
$paths = Video::getNewVideoFilename();
|
||||||
$obj->setTitle($infoObj->title);
|
$filename = $paths['filename'];
|
||||||
$obj->setClean_title($infoObj->title);
|
$filename = $obj->setFilename($filename);
|
||||||
$obj->setDuration($infoObj->duration);
|
if (is_object($infoObj)) {
|
||||||
$obj->setDescription($infoObj->description);
|
$obj->setTitle($infoObj->title);
|
||||||
file_put_contents($global['systemRootPath'] . "videos/{$filename}.jpg", base64_decode($infoObj->thumbs64));
|
$obj->setClean_title($infoObj->title);
|
||||||
}
|
$obj->setDuration($infoObj->duration);
|
||||||
$_POST['videoLinkType'] = "embed";
|
$obj->setDescription($infoObj->description);
|
||||||
} elseif (empty($_POST['id'])) {
|
file_put_contents($global['systemRootPath'] . "videos/{$filename}.jpg", base64_decode($infoObj->thumbs64));
|
||||||
$paths = Video::getNewVideoFilename();
|
}
|
||||||
$filename = $paths['filename'];
|
$_POST['videoLinkType'] = "embed";
|
||||||
$filename = $obj->setFilename($filename);
|
} elseif (empty($_POST['id'])) {
|
||||||
$obj->setTitle($path_parts["filename"]);
|
$paths = Video::getNewVideoFilename();
|
||||||
$obj->setClean_title($path_parts["filename"]);
|
$filename = $paths['filename'];
|
||||||
$obj->setDuration("");
|
$filename = $obj->setFilename($filename);
|
||||||
$obj->setDescription(@$_POST['description']);
|
$obj->setTitle($path_parts["filename"]);
|
||||||
$_POST['videoLinkType'] = "linkVideo";
|
$obj->setClean_title($path_parts["filename"]);
|
||||||
}
|
$obj->setDuration("");
|
||||||
$obj->setVideoLink($_POST['videoLink']);
|
$obj->setDescription(@$_POST['description']);
|
||||||
|
$_POST['videoLinkType'] = "linkVideo";
|
||||||
if (in_array($extension, $audioLinks) || in_array($extension, $videoLinks)) {
|
}
|
||||||
if (in_array($extension, $audioLinks)) {
|
$obj->setVideoLink($_POST['videoLink']);
|
||||||
$obj->setType('linkAudio');
|
|
||||||
} else {
|
if (in_array($extension, $audioLinks) || in_array($extension, $videoLinks)) {
|
||||||
$obj->setType('linkVideo');
|
if (in_array($extension, $audioLinks)) {
|
||||||
}
|
$obj->setType('linkAudio');
|
||||||
} elseif (!empty($obj->getType())) {
|
} else {
|
||||||
$obj->setType('embed');
|
$obj->setType('linkVideo');
|
||||||
}
|
}
|
||||||
|
} elseif (!empty($obj->getType())) {
|
||||||
if (!empty($_POST['videoLinkType'])) {
|
$obj->setType('embed');
|
||||||
$obj->setType($_POST['videoLinkType']);
|
}
|
||||||
}
|
|
||||||
if (empty($_POST['id'])) {
|
if (!empty($_POST['videoLinkType'])) {
|
||||||
$obj->setStatus('a');
|
$obj->setType($_POST['videoLinkType']);
|
||||||
}
|
}
|
||||||
} elseif (!empty($obj->getType()) && ($obj->getType() == 'video' || $obj->getType() == 'serie' || $obj->getType() == 'audio')) {
|
if (empty($_POST['id'])) {
|
||||||
$obj->setVideoLink("");
|
$obj->setStatus('a');
|
||||||
}
|
}
|
||||||
|
} elseif (!empty($obj->getType()) && ($obj->getType() == 'video' || $obj->getType() == 'serie' || $obj->getType() == 'audio')) {
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
$obj->setVideoLink("");
|
||||||
if (!empty($_POST['isArticle'])) {
|
}
|
||||||
$obj->setType("article");
|
|
||||||
if (empty($_POST['id'])) {
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
$obj->setStatus('a');
|
if (!empty($_POST['isArticle'])) {
|
||||||
}
|
$obj->setType("article");
|
||||||
$paths = Video::getNewVideoFilename();
|
if (empty($_POST['id'])) {
|
||||||
$filename = $paths['filename'];
|
$obj->setStatus('a');
|
||||||
$filename = $obj->setFilename($filename);
|
}
|
||||||
}
|
$paths = Video::getNewVideoFilename();
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
$filename = $paths['filename'];
|
||||||
$obj->setNext_videos_id($_POST['next_videos_id']);
|
$filename = $obj->setFilename($filename);
|
||||||
if (!empty($_POST['description'])) {
|
}
|
||||||
$obj->setDescription($_POST['description']);
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
}
|
$obj->setNext_videos_id($_POST['next_videos_id']);
|
||||||
if (empty($advancedCustomUser->userCanNotChangeCategory) || Permissions::canModerateVideos()) {
|
if (!empty($_POST['description'])) {
|
||||||
$obj->setCategories_id($_POST['categories_id']);
|
$obj->setDescription($_POST['description']);
|
||||||
}
|
}
|
||||||
|
if (empty($advancedCustomUser->userCanNotChangeCategory) || Permissions::canModerateVideos()) {
|
||||||
if (empty($advancedCustomUser->userCanNotChangeUserGroup) || Permissions::canModerateVideos()) {
|
$obj->setCategories_id($_POST['categories_id']);
|
||||||
$obj->setVideoGroups(empty($_POST['videoGroups']) ? [] : $_POST['videoGroups']);
|
}
|
||||||
}
|
|
||||||
|
if (empty($advancedCustomUser->userCanNotChangeUserGroup) || Permissions::canModerateVideos()) {
|
||||||
$externalOptions = new stdClass();
|
$obj->setVideoGroups(empty($_POST['videoGroups']) ? [] : $_POST['videoGroups']);
|
||||||
|
}
|
||||||
$externalOptionsOriginal = json_decode($obj->getExternalOptions());
|
|
||||||
if (!empty($externalOptionsOriginal) && is_object($externalOptionsOriginal)) {
|
$externalOptions = new stdClass();
|
||||||
foreach ($externalOptionsOriginal as $key => $value) {
|
|
||||||
$externalOptions->$key = $value;
|
$externalOptionsOriginal = json_decode($obj->getExternalOptions());
|
||||||
}
|
if (!empty($externalOptionsOriginal) && is_object($externalOptionsOriginal)) {
|
||||||
}
|
foreach ($externalOptionsOriginal as $key => $value) {
|
||||||
|
$externalOptions->$key = $value;
|
||||||
$externalOptionsPost = json_decode(@$_POST['externalOptions']);
|
}
|
||||||
if (!empty($externalOptionsPost) && is_object($externalOptionsPost)) {
|
}
|
||||||
foreach ($externalOptionsPost as $key => $value) {
|
|
||||||
$externalOptions->$key = $value;
|
$externalOptionsPost = json_decode(@$_POST['externalOptions']);
|
||||||
}
|
if (!empty($externalOptionsPost) && is_object($externalOptionsPost)) {
|
||||||
}
|
foreach ($externalOptionsPost as $key => $value) {
|
||||||
|
$externalOptions->$key = $value;
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
}
|
||||||
$obj->setCan_download(@$_POST['can_download']);
|
}
|
||||||
$obj->setCan_share(@$_POST['can_share']);
|
|
||||||
$obj->setOnly_for_paid(@$_POST['only_for_paid']);
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
$obj->setVideo_password(@$_POST['video_password']);
|
$obj->setCan_download(@$_POST['can_download']);
|
||||||
$obj->setTrailer1(@$_POST['trailer1']);
|
$obj->setCan_share(@$_POST['can_share']);
|
||||||
$obj->setRrating(@$_POST['rrating']);
|
$obj->setOnly_for_paid(@$_POST['only_for_paid']);
|
||||||
$obj->setExternalOptions($externalOptions);
|
$obj->setVideo_password(@$_POST['video_password']);
|
||||||
|
$obj->setTrailer1(@$_POST['trailer1']);
|
||||||
if(!empty($_REQUEST['users_id_company'])){
|
$obj->setRrating(@$_POST['rrating']);
|
||||||
$obj->setUsers_id_company(@$_REQUEST['users_id_company']);
|
$obj->setExternalOptions($externalOptions);
|
||||||
}
|
|
||||||
|
if(!empty($_REQUEST['users_id_company'])){
|
||||||
if ($advancedCustomUser->userCanChangeVideoOwner || Permissions::canModerateVideos() || Users_affiliations::isUserAffiliateOrCompanyToEachOther($obj->getUsers_id(), $_POST['users_id'])) {
|
$obj->setUsers_id_company(@$_REQUEST['users_id_company']);
|
||||||
$obj->setUsers_id($_POST['users_id']);
|
}
|
||||||
}
|
|
||||||
|
if ($advancedCustomUser->userCanChangeVideoOwner || Permissions::canModerateVideos() || Users_affiliations::isUserAffiliateOrCompanyToEachOther($obj->getUsers_id(), $_POST['users_id'])) {
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
$obj->setUsers_id($_POST['users_id']);
|
||||||
$resp = $obj->save(true);
|
}
|
||||||
// if is a new embed video
|
|
||||||
if (empty($_POST['id']) && ($obj->getType() == 'embed' || $obj->getType() == 'linkVideo')) {
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
AVideoPlugin::afterNewVideo($resp);
|
$resp = $obj->save(true);
|
||||||
}
|
// if is a new embed video
|
||||||
|
if (empty($_POST['id']) && ($obj->getType() == 'embed' || $obj->getType() == 'linkVideo')) {
|
||||||
if (User::isAdmin()) {
|
AVideoPlugin::afterNewVideo($resp);
|
||||||
$obj->updateViewsCount($_REQUEST['views_count']);
|
}
|
||||||
}
|
|
||||||
|
if (User::isAdmin()) {
|
||||||
AVideoPlugin::saveVideosAddNew($_POST, $resp);
|
$obj->updateViewsCount($_REQUEST['views_count']);
|
||||||
|
}
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
|
||||||
$obj = new stdClass();
|
AVideoPlugin::saveVideosAddNew($_POST, $resp);
|
||||||
|
|
||||||
$obj->status = !empty($resp);
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
$obj->msg = $msg;
|
$obj = new stdClass();
|
||||||
$obj->info = json_encode($info);
|
|
||||||
$obj->infoObj = json_encode($infoObj);
|
$obj->status = !empty($resp);
|
||||||
$obj->videos_id = intval($resp);
|
$obj->msg = $msg;
|
||||||
$obj->video = Video::getVideoLight($obj->videos_id);
|
$obj->info = json_encode($info);
|
||||||
if ($obj->video['status'] == Video::$statusActive) {
|
$obj->infoObj = json_encode($infoObj);
|
||||||
$obj->clearFirstPageCache = clearFirstPageCache();
|
$obj->videos_id = intval($resp);
|
||||||
//clearAllUsersSessionCache();
|
$obj->video = Video::getVideoLight($obj->videos_id);
|
||||||
}
|
if ($obj->video['status'] == Video::$statusActive) {
|
||||||
|
$obj->clearFirstPageCache = clearFirstPageCache();
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
//clearAllUsersSessionCache();
|
||||||
echo json_encode($obj);
|
}
|
||||||
|
|
||||||
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
|
echo json_encode($obj);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue