mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Add a caller timer
This commit is contained in:
parent
2c07a7705e
commit
dc9aec5bbe
9 changed files with 605 additions and 550 deletions
|
@ -504,8 +504,9 @@ abstract class ObjectYPT implements ObjectInterface
|
|||
if (empty($getCachesProcessed)) {
|
||||
$getCachesProcessed = [];
|
||||
}
|
||||
//if($name=='getVideosURL_V2video_220721204450_v21b7'){var_dump($name);exit;}
|
||||
$cachefile = self::getCacheFileName($name, false);
|
||||
//var_dump($cachefile);//exit;
|
||||
//if($name=='getVideosURL_V2video_220721204450_v21b7'){var_dump($cachefile);exit;}//exit;
|
||||
self::setLastUsedCacheFile($cachefile);
|
||||
//_error_log('getCache: cachefile '.$cachefile);
|
||||
if (!empty($_getCache[$name])) {
|
||||
|
|
|
@ -386,7 +386,7 @@ function safeString($text, $strict = false) {
|
|||
if ($strict) {
|
||||
$text = filter_var($text, FILTER_SANITIZE_STRING);
|
||||
//$text = cleanURLName($text);
|
||||
}
|
||||
}
|
||||
$text = trim($text);
|
||||
return $text;
|
||||
}
|
||||
|
@ -1332,7 +1332,9 @@ function getVideosURL_V2($fileName, $recreateCache = false) {
|
|||
|
||||
$TimeLog1 = "getVideosURL_V2($fileName) empty recreateCache";
|
||||
TimeLogStart($TimeLog1);
|
||||
$files = object_to_array(ObjectYPT::getCache($cacheName, $lifetime, true));
|
||||
//var_dump($cacheName, $lifetime);exit;
|
||||
$cache = ObjectYPT::getCache($cacheName, $lifetime, true);
|
||||
$files = object_to_array($cache);
|
||||
if (is_array($files)) {
|
||||
//_error_log("getVideosURL_V2: do NOT recreate lifetime = {$lifetime}");
|
||||
$preg_match_url = addcslashes(getCDN(), "/") . "videos";
|
||||
|
@ -2396,7 +2398,7 @@ function getTagIfExists($relativePath) {
|
|||
}
|
||||
}
|
||||
|
||||
function getImageTagIfExists($relativePath, $title='', $id='', $style='', $class='img img-responsive', $lazyLoad=false) {
|
||||
function getImageTagIfExists($relativePath, $title = '', $id = '', $style = '', $class = 'img img-responsive', $lazyLoad = false) {
|
||||
global $global;
|
||||
$relativePathOriginal = $relativePath;
|
||||
$relativePath = getRelativePath($relativePath);
|
||||
|
@ -2404,83 +2406,83 @@ function getImageTagIfExists($relativePath, $title='', $id='', $style='', $class
|
|||
$wh = '';
|
||||
if (file_exists($file)) {
|
||||
// check if there is a thumbs
|
||||
if(!preg_match('/_thumbsV2.jpg/', $file)){
|
||||
if (!preg_match('/_thumbsV2.jpg/', $file)) {
|
||||
$thumbs = str_replace('.jpg', '_thumbsV2.jpg', $file);
|
||||
if(file_exists($thumbs)){
|
||||
if (file_exists($thumbs)) {
|
||||
$file = $thumbs;
|
||||
}
|
||||
}
|
||||
$file = createWebPIfNotExists($file);
|
||||
|
||||
|
||||
$url = getURL(getRelativePath($file));
|
||||
$image_info = getimagesize($file);
|
||||
$wh = $image_info[3];
|
||||
} else if (isValidURL($relativePathOriginal)) {
|
||||
$url = $relativePathOriginal;
|
||||
} else {
|
||||
return '<!-- invalid URL '.$relativePathOriginal.' -->';
|
||||
return '<!-- invalid URL ' . $relativePathOriginal . ' -->';
|
||||
}
|
||||
if(empty($title)){
|
||||
if (empty($title)) {
|
||||
$title = basename($relativePath);
|
||||
}
|
||||
$title = safeString($title);
|
||||
$img = "<img style=\"{$style}\" alt=\"{$title}\" title=\"{$title}\" id=\"{$id}\" class=\"{$class}\" {$wh} ";
|
||||
if($lazyLoad){
|
||||
if(is_string($lazyLoad)){
|
||||
if ($lazyLoad) {
|
||||
if (is_string($lazyLoad)) {
|
||||
$loading = getURL($lazyLoad);
|
||||
}else{
|
||||
} else {
|
||||
$loading = getURL('view/img/loading-gif.png');
|
||||
}
|
||||
$img .= " src=\"{$loading}\" data-src=\"{$url}\" ";
|
||||
}else{
|
||||
} else {
|
||||
$img .= " src=\"{$url}\" ";
|
||||
}
|
||||
$img .= "/>";
|
||||
|
||||
|
||||
return $img;
|
||||
}
|
||||
|
||||
function createWebPIfNotExists($path){
|
||||
if(version_compare(PHP_VERSION, '8.0.0') < 0 || !file_exists($path)){
|
||||
function createWebPIfNotExists($path) {
|
||||
if (version_compare(PHP_VERSION, '8.0.0') < 0 || !file_exists($path)) {
|
||||
return $path;
|
||||
}
|
||||
$extension = pathinfo($path, PATHINFO_EXTENSION);
|
||||
if($extension!=='jpg'){
|
||||
if ($extension !== 'jpg') {
|
||||
return $path;
|
||||
}
|
||||
$nextGenPath = str_replace('.jpg', '_jpg.webp', $path);
|
||||
|
||||
if(!file_exists($nextGenPath)){
|
||||
|
||||
if (!file_exists($nextGenPath)) {
|
||||
convertImage($path, $nextGenPath, 70);
|
||||
}
|
||||
return $nextGenPath;
|
||||
}
|
||||
|
||||
function getVideoImagewithHoverAnimation($relativePath, $relativePathHoverAnimation='', $title=''){
|
||||
function getVideoImagewithHoverAnimation($relativePath, $relativePathHoverAnimation = '', $title = '') {
|
||||
$id = uniqid();
|
||||
$img = getImageTagIfExists($relativePath, $title, "thumbsJPG{$id}", '', 'thumbsJPG img img-responsive').PHP_EOL;
|
||||
if(!empty($relativePathHoverAnimation) && empty($_REQUEST['noImgGif'])){
|
||||
$img .= getImageTagIfExists($relativePathHoverAnimation, $title, "thumbsGIF{$id}", 'position: absolute; top: 0;', 'thumbsGIF img img-responsive ', true).PHP_EOL;
|
||||
$img = getImageTagIfExists($relativePath, $title, "thumbsJPG{$id}", '', 'thumbsJPG img img-responsive') . PHP_EOL;
|
||||
if (!empty($relativePathHoverAnimation) && empty($_REQUEST['noImgGif'])) {
|
||||
$img .= getImageTagIfExists($relativePathHoverAnimation, $title, "thumbsGIF{$id}", 'position: absolute; top: 0;', 'thumbsGIF img img-responsive ', true) . PHP_EOL;
|
||||
}
|
||||
return '<div class="thumbsImage">'.$img.'</div>';
|
||||
return '<div class="thumbsImage">' . $img . '</div>';
|
||||
}
|
||||
|
||||
function getRelativePath($path){
|
||||
function getRelativePath($path) {
|
||||
global $global;
|
||||
$relativePath = '';
|
||||
$parts = explode('view/img/', $path);
|
||||
|
||||
if(!empty($parts[1])){
|
||||
$relativePath = 'view/img/'.$parts[1];
|
||||
|
||||
if (!empty($parts[1])) {
|
||||
$relativePath = 'view/img/' . $parts[1];
|
||||
}
|
||||
if(empty($relativePath)){
|
||||
if (empty($relativePath)) {
|
||||
$parts = explode('videos/', $path);
|
||||
if(!empty($parts[1])){
|
||||
$relativePath = 'videos/'.$parts[1];
|
||||
if (!empty($parts[1])) {
|
||||
$relativePath = 'videos/' . $parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($relativePath)){
|
||||
|
||||
if (empty($relativePath)) {
|
||||
$relativePath = $path;
|
||||
}
|
||||
$parts2 = explode('?', $relativePath);
|
||||
|
@ -3495,7 +3497,7 @@ function rrmdir($dir) {
|
|||
}
|
||||
if (rmdir($dir)) {
|
||||
return true;
|
||||
} else if(is_dir($dir)){
|
||||
} else if (is_dir($dir)) {
|
||||
_error_log('rrmdir: could not delete folder ' . $dir);
|
||||
return false;
|
||||
}
|
||||
|
@ -5168,16 +5170,20 @@ function isValidURLOrPath($str, $insideCacheOrTmpDirOnly = true) {
|
|||
_error_log('isValidURLOrPath return false (is php file) ' . $str);
|
||||
return false;
|
||||
}
|
||||
$cacheDir = "{$global['systemRootPath']}videos/";
|
||||
if (str_starts_with($absolutePath, $absolutePathTmp) || str_starts_with($absolutePath, '/var/www/') || str_starts_with($absolutePath, $absolutePathCache)) {
|
||||
if (
|
||||
str_starts_with($absolutePath, $absolutePathTmp) ||
|
||||
str_starts_with($absolutePath, '/var/www/') ||
|
||||
str_starts_with($absolutePath, $absolutePathCache) ||
|
||||
str_starts_with($absolutePath, $global['systemRootPath']) ||
|
||||
str_starts_with($absolutePath, getVideosDir())) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
_error_log('isValidURLOrPath return false not valid absolute path 1 ' . $absolutePath);
|
||||
_error_log('isValidURLOrPath return false not valid absolute path 2 ' . $absolutePathTmp);
|
||||
_error_log('isValidURLOrPath return false not valid absolute path 3 ' . $absolutePathCache);
|
||||
//_error_log('isValidURLOrPath return false not valid absolute path 1 ' . $absolutePath);
|
||||
//_error_log('isValidURLOrPath return false not valid absolute path 2 ' . $absolutePathTmp);
|
||||
//_error_log('isValidURLOrPath return false not valid absolute path 3 ' . $absolutePathCache);
|
||||
}
|
||||
//_error_log('isValidURLOrPath return false '.$str);
|
||||
return false;
|
||||
|
@ -5843,6 +5849,7 @@ function _json_encode($object) {
|
|||
}
|
||||
|
||||
function _json_decode($object) {
|
||||
global $global;
|
||||
if (empty($object)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -6696,69 +6703,6 @@ function playHLSasMP4($filepath) {
|
|||
exit;
|
||||
}
|
||||
|
||||
function m3u8ToMP4($input) {
|
||||
$videosDir = getVideosDir();
|
||||
$outputfilename = str_replace($videosDir, "", $input);
|
||||
$parts = explode("/", $outputfilename);
|
||||
$resolution = Video::getResolutionFromFilename($input);
|
||||
$outputfilename = $parts[0] . "_{$resolution}_.mp4";
|
||||
$outputpath = "{$videosDir}cache/downloads/{$outputfilename}";
|
||||
$msg = '';
|
||||
$error = true;
|
||||
make_path($outputpath);
|
||||
if (empty($outputfilename)) {
|
||||
$msg = "downloadHLS: empty outputfilename {$outputfilename}";
|
||||
_error_log($msg);
|
||||
return ['error' => $error, 'msg' => $msg];
|
||||
}
|
||||
_error_log("downloadHLS: m3u8ToMP4($input)");
|
||||
//var_dump(!preg_match('/^http/i', $input), filesize($input), preg_match('/.m3u8$/i', $input));
|
||||
$ism3u8 = preg_match('/.m3u8$/i', $input);
|
||||
if (!preg_match('/^http/i', $input) && (filesize($input) <= 10 || $ism3u8)) { // dummy file
|
||||
$filepath = escapeshellcmd(pathToRemoteURL($input, true, true));
|
||||
if ($ism3u8 && !preg_match('/.m3u8$/i', $filepath)) {
|
||||
$filepath = addLastSlash($filepath) . 'index.m3u8';
|
||||
}
|
||||
|
||||
$token = getToken(60);
|
||||
$filepath = addQueryStringParameter($filepath, 'globalToken', $token);
|
||||
} else {
|
||||
$filepath = escapeshellcmd($input);
|
||||
}
|
||||
|
||||
if (is_dir($filepath)) {
|
||||
$filepath = addLastSlash($filepath) . 'index.m3u8';
|
||||
}
|
||||
|
||||
$outputpath = escapeshellcmd($outputpath);
|
||||
if (!file_exists($outputpath)) {
|
||||
$command = get_ffmpeg() . " -allowed_extensions ALL -y -i \"{$filepath}\" -c:v copy -c:a copy -bsf:a aac_adtstoasc -strict -2 {$outputpath}";
|
||||
$msg1 = "downloadHLS: Exec Command ({$command})";
|
||||
_error_log($msg1);
|
||||
//var_dump($outputfilename, $command, $_GET, $filepath);exit;
|
||||
exec($command . " 2>&1", $output, $return);
|
||||
if (!empty($return)) {
|
||||
$msg2 = "downloadHLS: ERROR 1 " . implode(PHP_EOL, $output);
|
||||
_error_log($msg2);
|
||||
|
||||
$command = get_ffmpeg() . " -y -i \"{$filepath}\" -c:v copy -c:a copy -bsf:a aac_adtstoasc -strict -2 {$outputpath}";
|
||||
//var_dump($outputfilename, $command, $_GET, $filepath);exit;
|
||||
exec($command . " 2>&1", $output, $return);
|
||||
if (!empty($return)) {
|
||||
$msg3 = "downloadHLS: ERROR 2 " . implode(PHP_EOL, $output);
|
||||
$finalMsg = $msg1 . PHP_EOL . $msg2 . PHP_EOL . $msg3;
|
||||
_error_log($msg3);
|
||||
return ['error' => $error, 'msg' => $finalMsg];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$msg = "downloadHLS: outputpath already exists ({$outputpath})";
|
||||
_error_log($msg);
|
||||
}
|
||||
$error = false;
|
||||
return ['error' => $error, 'msg' => $msg, 'path' => $outputpath, 'filename' => $outputfilename];
|
||||
}
|
||||
|
||||
function getSocialModal($videos_id, $url = "", $title = "") {
|
||||
global $global;
|
||||
$video['id'] = $videos_id;
|
||||
|
@ -6886,6 +6830,123 @@ function get_ffmpeg($ignoreGPU = false) {
|
|||
return $ffmpeg . $complement;
|
||||
}
|
||||
|
||||
function convertVideoFileWithFFMPEG($fromFileLocation, $toFileLocation, $try = 0) {
|
||||
$localFileLock = getVideosDir() . "{$relativeFilename}.lock";
|
||||
if (file_exists($localFileLock)) {
|
||||
_error_log('convertVideoFileWithFFMPEG: download from CDN There is a process running for ' . $localFile);
|
||||
return false;
|
||||
}
|
||||
make_path($toFileLocation);
|
||||
file_put_contents($localFileLock, time());
|
||||
$fromFileLocationEscaped = escapeshellarg($fromFileLocation);
|
||||
$toFileLocationEscaped = escapeshellarg($toFileLocation);
|
||||
|
||||
$format = pathinfo($toFileLocation, PATHINFO_EXTENSION);
|
||||
|
||||
if ($format == 'mp3') {
|
||||
switch ($try) {
|
||||
case 0:
|
||||
$command = get_ffmpeg() . " -i \"{$fromFileLocation}\" -c:a libmp3lame \"{$toFileLocation}\"";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch ($try) {
|
||||
case 0:
|
||||
$command = get_ffmpeg() . " -i {$fromFileLocationEscaped} -c copy {$toFileLocationEscaped}";
|
||||
break;
|
||||
case 1:
|
||||
$command = get_ffmpeg() . " -allowed_extensions ALL -y -i {$fromFileLocationEscaped} -c:v copy -c:a copy -bsf:a aac_adtstoasc -strict -2 {$toFileLocationEscaped}";
|
||||
break;
|
||||
case 2:
|
||||
$command = get_ffmpeg() . " -y -i {$fromFileLocationEscaped} -c:v copy -c:a copy -bsf:a aac_adtstoasc -strict -2 {$toFileLocationEscaped}";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$progressFile = getConvertVideoFileWithFFMPEGProgressFilename($toFileLocation);
|
||||
$progressFileEscaped = escapeshellarg($progressFile);
|
||||
$command .= " 1> {$progressFileEscaped} 2>&1";
|
||||
_error_log("convertVideoFileWithFFMPEG try[{$try}]: " . $command);
|
||||
session_write_close();
|
||||
_mysql_close();
|
||||
exec($command, $output, $return);
|
||||
_session_start();
|
||||
_mysql_connect();
|
||||
_error_log("convertVideoFileWithFFMPEG try[{$try}] output: " . json_encode($output));
|
||||
|
||||
unlink($localFileLock);
|
||||
|
||||
return ['return'=> $return, 'output'=>$output, 'command'=>$command, 'fromFileLocation'=>$fromFileLocation, 'toFileLocation'=>$toFileLocation, 'progressFile'=>$progressFile];
|
||||
}
|
||||
|
||||
function m3u8ToMP4($input) {
|
||||
$videosDir = getVideosDir();
|
||||
$outputfilename = str_replace($videosDir, "", $input);
|
||||
$parts = explode("/", $outputfilename);
|
||||
$resolution = Video::getResolutionFromFilename($input);
|
||||
$outputfilename = $parts[0] . "_{$resolution}_.mp4";
|
||||
$outputpath = "{$videosDir}cache/downloads/{$outputfilename}";
|
||||
$msg = '';
|
||||
$error = true;
|
||||
if (empty($outputfilename)) {
|
||||
$msg = "downloadHLS: empty outputfilename {$outputfilename}";
|
||||
_error_log($msg);
|
||||
return ['error' => $error, 'msg' => $msg];
|
||||
}
|
||||
_error_log("downloadHLS: m3u8ToMP4($input)");
|
||||
//var_dump(!preg_match('/^http/i', $input), filesize($input), preg_match('/.m3u8$/i', $input));
|
||||
$ism3u8 = preg_match('/.m3u8$/i', $input);
|
||||
if (!preg_match('/^http/i', $input) && (filesize($input) <= 10 || $ism3u8)) { // dummy file
|
||||
$filepath = pathToRemoteURL($input, true, true);
|
||||
if ($ism3u8 && !preg_match('/.m3u8$/i', $filepath)) {
|
||||
$filepath = addLastSlash($filepath) . 'index.m3u8';
|
||||
}
|
||||
|
||||
$token = getToken(60);
|
||||
$filepath = addQueryStringParameter($filepath, 'globalToken', $token);
|
||||
} else {
|
||||
$filepath = escapeshellcmd($input);
|
||||
}
|
||||
|
||||
if (is_dir($filepath)) {
|
||||
$filepath = addLastSlash($filepath) . 'index.m3u8';
|
||||
}
|
||||
|
||||
if (!file_exists($outputpath)) {
|
||||
var_dump($filepath, $outputpath);exit;
|
||||
$return = convertVideoFileWithFFMPEG($filepath, $outputpath);
|
||||
var_dump($return);exit;
|
||||
if (empty($return)) {
|
||||
$msg3 = "downloadHLS: ERROR 2 " . implode(PHP_EOL, $output);
|
||||
$finalMsg = $msg1 . PHP_EOL . $msg2 . PHP_EOL . $msg3;
|
||||
_error_log($msg3);
|
||||
return ['error' => $error, 'msg' => $finalMsg];
|
||||
}
|
||||
} else {
|
||||
$msg = "downloadHLS: outputpath already exists ({$outputpath})";
|
||||
_error_log($msg);
|
||||
}
|
||||
$error = false;
|
||||
return ['error' => $error, 'msg' => $msg, 'path' => $outputpath, 'filename' => $outputfilename];
|
||||
}
|
||||
|
||||
|
||||
function getConvertVideoFileWithFFMPEGProgressFilename($toFileLocation) {
|
||||
$progressFile = $toFileLocation . '.log';
|
||||
return $progressFile;
|
||||
}
|
||||
|
||||
function convertVideoToDownlaodProgress($toFileLocation) {
|
||||
$progressFile = getConvertVideoFileWithFFMPEGProgressFilename($toFileLocation);
|
||||
return parseFFMPEGProgress($progressFile);
|
||||
}
|
||||
|
||||
function get_php() {
|
||||
global $global;
|
||||
$php = 'php ';
|
||||
|
@ -8020,20 +8081,21 @@ function getCDNOrURL($url, $type = 'CDN', $id = 0) {
|
|||
|
||||
function replaceCDNIfNeed($url, $type = 'CDN', $id = 0) {
|
||||
$cdn = getCDN($type, $id);
|
||||
if(!empty($_GET['debug'])){
|
||||
$obj = AVideoPlugin::getDataObject('Blackblaze_B2');
|
||||
var_dump($url, $type, $id, $cdn, $obj->CDN_Link);exit;
|
||||
if (!empty($_GET['debug'])) {
|
||||
$obj = AVideoPlugin::getDataObject('Blackblaze_B2');
|
||||
var_dump($url, $type, $id, $cdn, $obj->CDN_Link);
|
||||
exit;
|
||||
}
|
||||
if (empty($cdn)) {
|
||||
if($type == 'CDN_B2'){
|
||||
$obj = AVideoPlugin::getDataObject('Blackblaze_B2');
|
||||
if(isValidURL($obj->CDN_Link)){
|
||||
if ($type == 'CDN_B2') {
|
||||
$obj = AVideoPlugin::getDataObject('Blackblaze_B2');
|
||||
if (isValidURL($obj->CDN_Link)) {
|
||||
$basename = basename($url);
|
||||
return addLastSlash($obj->CDN_Link).$basename;
|
||||
return addLastSlash($obj->CDN_Link) . $basename;
|
||||
}
|
||||
}else if($type == 'CDN_S3'){
|
||||
$obj = AVideoPlugin::getDataObject('AWS_S3');
|
||||
if(isValidURL($obj->CDN_Link)){
|
||||
} else if ($type == 'CDN_S3') {
|
||||
$obj = AVideoPlugin::getDataObject('AWS_S3');
|
||||
if (isValidURL($obj->CDN_Link)) {
|
||||
$cdn = $obj->CDN_Link;
|
||||
}
|
||||
}
|
||||
|
@ -8041,7 +8103,7 @@ function replaceCDNIfNeed($url, $type = 'CDN', $id = 0) {
|
|||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return str_replace(parse_url($url, PHP_URL_HOST), parse_url($cdn, PHP_URL_HOST), $url);
|
||||
}
|
||||
|
||||
|
@ -9065,17 +9127,17 @@ function deleteInvalidImage($filepath) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add the twitterjs if the link is present
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
function addTwitterJS($text){
|
||||
if(preg_match('/href=.+twitter.com.+ref_src=.+/', $text)){
|
||||
if(!preg_match('/platform.twitter.com.widgets.js/', $text)){
|
||||
function addTwitterJS($text) {
|
||||
if (preg_match('/href=.+twitter.com.+ref_src=.+/', $text)) {
|
||||
if (!preg_match('/platform.twitter.com.widgets.js/', $text)) {
|
||||
$text .= '<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>';
|
||||
}
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3349,10 +3349,11 @@ if (!class_exists('Video')) {
|
|||
return $__getPaths[$videoFilename];
|
||||
}
|
||||
$cleanVideoFilename = self::getCleanFilenameFromFile($videoFilename);
|
||||
//var_dump($videoFilename, $path,$cleanVideoFilename);
|
||||
$videosDir = self::getStoragePath();
|
||||
|
||||
$path = addLastSlash("{$videosDir}{$cleanVideoFilename}");
|
||||
|
||||
|
||||
$path = fixPath($path);
|
||||
if ($createDir) {
|
||||
make_path(addLastSlash($path));
|
||||
|
@ -3371,11 +3372,16 @@ if (!class_exists('Video')) {
|
|||
$videosDir = self::getStoragePath();
|
||||
$videoFilename = str_replace($videosDir, '', $videoFilename);
|
||||
$paths = Video::getPaths($videoFilename, $createDir);
|
||||
if (preg_match('/index.m3u8$/', $videoFilename)) {
|
||||
//var_dump($paths);
|
||||
if (preg_match('/index.(m3u8|mp4)$/', $videoFilename)) {
|
||||
$paths['path'] = rtrim($paths['path'], DIRECTORY_SEPARATOR);
|
||||
$paths['path'] = rtrim($paths['path'], '/');
|
||||
$videoFilename = str_replace($paths['relative'], '', $videoFilename);
|
||||
$videoFilename = str_replace($paths['filename'], '', $videoFilename);
|
||||
}
|
||||
return "{$paths['path']}{$videoFilename}";
|
||||
$newPath = addLastSlash($paths['path']). "{$videoFilename}";
|
||||
//var_dump($newPath);
|
||||
return $newPath;
|
||||
}
|
||||
|
||||
public static function getURLToFile($videoFilename, $createDir = false) {
|
||||
|
@ -3511,9 +3517,11 @@ if (!class_exists('Video')) {
|
|||
}
|
||||
$filename = fixPath($filename);
|
||||
$filename = str_replace(getVideosDir(), '', $filename);
|
||||
if (preg_match('/videos[\/\\\]([^\/\\\]+)[\/\\\].*index.m3u8$/', $filename, $matches)) {
|
||||
if (preg_match('/videos[\/\\\]([^\/\\\]+)[\/\\\].*index.(m3u8|mp4|mp3)$/', $filename, $matches)) {
|
||||
//var_dump($filename, $matches);
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
$search = ['_Low', '_SD', '_HD', '_thumbsV2', '_thumbsSmallV2', '_thumbsSprit', '_roku', '_portrait', '_portrait_thumbsV2', '_portrait_thumbsSmallV2', '_thumbsV2_jpg', '_spectrum', '_tvg', '.notfound'];
|
||||
|
||||
if (!empty($global['langs_codes_values_withdot']) && is_array($global['langs_codes_values_withdot'])) {
|
||||
|
|
|
@ -1,272 +1,266 @@
|
|||
<?php
|
||||
|
||||
require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php';
|
||||
require_once $global['systemRootPath'] . 'plugin/CDN/Storage/CDNStorage.php';
|
||||
|
||||
class CDN extends PluginAbstract
|
||||
{
|
||||
public function getTags()
|
||||
{
|
||||
return [
|
||||
PluginTags::$RECOMMENDED,
|
||||
PluginTags::$LIVE,
|
||||
PluginTags::$PLAYER,
|
||||
PluginTags::$STORAGE,
|
||||
];
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
global $global;
|
||||
$txt = "With our CDN we will provide you a highly-distributed platform of servers that helps minimize delays in loading web page content "
|
||||
. "by reducing the physical distance between the server and the user. This helps users around the world view the same high-quality "
|
||||
. "content without slow loading times";
|
||||
$txt .= "<br>If you are using the CDN Storage, add this into your crontab <code>2 1 * * * php {$global['systemRootPath']}plugin/CDN/tools/moveMissingFiles.php</code>. "
|
||||
. "This command will daily check your files and free some space into your server";
|
||||
$help = "";
|
||||
return $txt . $help;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "CDN";
|
||||
}
|
||||
|
||||
public function getUUID()
|
||||
{
|
||||
return "CDN73225-3807-4167-ba81-0509dd280e06";
|
||||
}
|
||||
|
||||
public function getPluginVersion()
|
||||
{
|
||||
return "2.0";
|
||||
}
|
||||
|
||||
public function getEmptyDataObject()
|
||||
{
|
||||
global $global, $config;
|
||||
$obj = new stdClass();
|
||||
$obj->key = "";
|
||||
$obj->CDN = "";
|
||||
$obj->CDN_S3 = "";
|
||||
$obj->CDN_B2 = "";
|
||||
$obj->CDN_FTP = "";
|
||||
// this is a JSON with site_id + URL
|
||||
$obj->CDN_YPTStorage = ""; // array
|
||||
$obj->CDN_Live = "";
|
||||
// this is a JSON with servers_id + URL
|
||||
$obj->CDN_LiveServers = ""; // array
|
||||
$obj->enable_storage = false;
|
||||
$obj->storage_autoupload_new_videos = true;
|
||||
$obj->storage_users_can_choose_storage = true;
|
||||
$obj->storage_username = "";
|
||||
$obj->storage_password = "";
|
||||
$obj->storage_hostname = "";
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getVideosManagerListButton()
|
||||
{
|
||||
$btn = '';
|
||||
$videoHLSObj = AVideoPlugin::getDataObjectIfEnabled('VideoHLS');
|
||||
if(!empty($videoHLSObj)){
|
||||
if (!empty($videoHLSObj->saveMP4CopyOnCDNStorageToAllowDownload) || !empty($videoHLSObj->saveMP3CopyOnCDNStorageToAllowDownload)) {
|
||||
$btn .= '<button type="button" class="btn btn-default btn-light btn-sm btn-xs btn-block " onclick="avideoModalIframeSmall(webSiteRootURL+\\\'plugin/CDN/downloadButtons.php?videos_id=\'+ row.id +\'\\\');" ><i class="fas fa-download"></i> Download</button>';
|
||||
}
|
||||
}
|
||||
if (self::userCanMoveVideoStorage()) {
|
||||
$btn .= '<button type="button" class="btn btn-default btn-light btn-sm btn-xs btn-block " onclick="avideoModalIframeSmall(webSiteRootURL+\\\'plugin/CDN/Storage/syncVideo.php?videos_id=\'+ row.id +\'\\\');" ><i class="fas fa-project-diagram"></i> CDN Storage</button>';
|
||||
}
|
||||
return $btn;
|
||||
}
|
||||
|
||||
public function getPluginMenu()
|
||||
{
|
||||
global $global;
|
||||
$fileAPIName = $global['systemRootPath'] . 'plugin/CDN/pluginMenu.html';
|
||||
$content = file_get_contents($fileAPIName);
|
||||
$obj = $this->getDataObject();
|
||||
|
||||
$url = "https://youphp.tube/marketplace/CDN/iframe.php?hash={hash}";
|
||||
|
||||
$url = addQueryStringParameter($url, 'hash', $obj->key);
|
||||
$url = addQueryStringParameter($url, 'webSiteRootURL', $global['webSiteRootURL']);
|
||||
|
||||
$cdnMenu = str_replace('{url}', $url, $content);
|
||||
$storageMenu = '';
|
||||
if (self::userCanMoveVideoStorage()) {
|
||||
$fileStorageMenu = $global['systemRootPath'] . 'plugin/CDN/Storage/pluginMenu.html';
|
||||
$storageMenu = file_get_contents($fileStorageMenu);
|
||||
}
|
||||
return $cdnMenu.$storageMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $type enum(CDN, CDN_S3,CDN_B2,CDN_YPTStorage,CDN_Live,CDN_LiveServers)
|
||||
* @param type $id the ID of the URL in case the CDN is an array
|
||||
* @return boolean
|
||||
*/
|
||||
public static function getURL($type = 'CDN', $id = 0)
|
||||
{
|
||||
$obj = AVideoPlugin::getObjectData('CDN');
|
||||
|
||||
if (empty($obj->{$type})) {
|
||||
return false;
|
||||
}
|
||||
if (isIPPrivate(getDomain())) {
|
||||
_error_log('The CDN will not work under a private network $type=' . $type);
|
||||
return false;
|
||||
}
|
||||
$url = '';
|
||||
switch ($type) {
|
||||
case 'CDN':
|
||||
case 'CDN_S3':
|
||||
case 'CDN_B2':
|
||||
case 'CDN_FTP':
|
||||
case 'CDN_Live':
|
||||
$url = $obj->{$type};
|
||||
break;
|
||||
case 'CDN_LiveServers':
|
||||
case 'CDN_YPTStorage':
|
||||
if (!empty($id)) {
|
||||
$json = _json_decode($obj->{$type});
|
||||
//var_dump(!empty($json), is_object($json), is_array($json));//exit;
|
||||
if (!empty($json) && (is_object($json) || is_array($json))) {
|
||||
foreach ($json as $value) {
|
||||
if ($value->id == $id) {
|
||||
$url = $value->URLToCDN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//var_dump($url);exit;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($url) && isValidURL($url)) {
|
||||
return addLastSlash($url);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getCDN_S3URL()
|
||||
{
|
||||
$plugin = AVideoPlugin::getDataObjectIfEnabled('AWS_S3');
|
||||
$CDN_S3 = '';
|
||||
if (!empty($plugin)) {
|
||||
$region = trim($plugin->region);
|
||||
$bucket_name = trim($plugin->bucket_name);
|
||||
$endpoint = trim($plugin->endpoint);
|
||||
if (!empty($endpoint)) {
|
||||
$CDN_S3 = str_replace('https://', "https://{$bucket_name}.", $endpoint);
|
||||
} elseif (!empty($plugin->region)) {
|
||||
$CDN_S3 = "https://{$bucket_name}.s3-accesspoint.{$region}.amazonaws.com";
|
||||
}
|
||||
if (!empty($resp->CDN_S3)) {
|
||||
$CDN_S3 = addLastSlash($resp->CDN_S3);
|
||||
}
|
||||
}
|
||||
return $CDN_S3;
|
||||
}
|
||||
|
||||
public static function getCDN_B2URL()
|
||||
{
|
||||
$CDN_B2 = '';
|
||||
$plugin = AVideoPlugin::getDataObjectIfEnabled('Blackblaze_B2');
|
||||
if (!empty($plugin)) {
|
||||
$b2 = new Blackblaze_B2();
|
||||
$CDN_B2 = $b2->getEndpoint();
|
||||
if (!empty($resp->CDN_B2)) {
|
||||
$CDN_B2 = addLastSlash($resp->CDN_B2);
|
||||
}
|
||||
}
|
||||
return $CDN_B2;
|
||||
}
|
||||
|
||||
public static function getCDN_FTPURL()
|
||||
{
|
||||
$CDN_FTP = '';
|
||||
$plugin = AVideoPlugin::getDataObjectIfEnabled('CDN');
|
||||
if (!empty($plugin)) {
|
||||
$CDN_FTP = addLastSlash($plugin->endpoint);
|
||||
}
|
||||
return $CDN_FTP;
|
||||
}
|
||||
|
||||
public static function getVideoTags($videos_id)
|
||||
{
|
||||
global $global;
|
||||
if (empty($videos_id)) {
|
||||
return [];
|
||||
}
|
||||
if (!Video::canEdit($videos_id)) {
|
||||
return [];
|
||||
}
|
||||
$video = Video::getVideoLight($videos_id);
|
||||
$sites_id = $video['sites_id'];
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->label = 'Storage';
|
||||
$isMoving = CDNStorage::isMoving($videos_id);
|
||||
if ($isMoving) {
|
||||
$obj->type = "danger";
|
||||
$obj->text = '<i class="fas fa-sync fa-spin"></i> ' . __('Moving');
|
||||
} elseif (empty($sites_id)) {
|
||||
$obj->type = "success";
|
||||
$obj->text = '<i class="fas fa-map-marker-alt"></i> ' . __('Local');
|
||||
} else {
|
||||
$obj->type = "warning";
|
||||
$obj->text = "<i class=\"fas fa-project-diagram\"></i> " . __('Storage');
|
||||
}
|
||||
//var_dump($obj);exit;
|
||||
return [$obj];
|
||||
}
|
||||
|
||||
|
||||
public function onEncoderNotifyIsDone($videos_id)
|
||||
{
|
||||
return $this->processNewVideo($videos_id);
|
||||
}
|
||||
|
||||
public function onUploadIsDone($videos_id)
|
||||
{
|
||||
return $this->processNewVideo($videos_id);
|
||||
}
|
||||
|
||||
private function processNewVideo($videos_id)
|
||||
{
|
||||
$obj = AVideoPlugin::getDataObjectIfEnabled('CDN');
|
||||
if ($obj->enable_storage) {
|
||||
if ($obj->storage_autoupload_new_videos) {
|
||||
CDNStorage::moveLocalToRemote($videos_id, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function userCanMoveVideoStorage()
|
||||
{
|
||||
$obj = AVideoPlugin::getDataObjectIfEnabled('CDN');
|
||||
if (empty($obj->enable_storage)) {
|
||||
return false;
|
||||
}
|
||||
if (User::isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
if (!empty($obj->storage_users_can_choose_storage) && User::canUpload()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFooterCode()
|
||||
{
|
||||
global $global;
|
||||
if (self::userCanMoveVideoStorage()) {
|
||||
include $global['systemRootPath'] . 'plugin/CDN/Storage/footer.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php';
|
||||
require_once $global['systemRootPath'] . 'plugin/CDN/Storage/CDNStorage.php';
|
||||
|
||||
class CDN extends PluginAbstract
|
||||
{
|
||||
public function getTags()
|
||||
{
|
||||
return [
|
||||
PluginTags::$RECOMMENDED,
|
||||
PluginTags::$LIVE,
|
||||
PluginTags::$PLAYER,
|
||||
PluginTags::$STORAGE,
|
||||
];
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
global $global;
|
||||
$txt = "With our CDN we will provide you a highly-distributed platform of servers that helps minimize delays in loading web page content "
|
||||
. "by reducing the physical distance between the server and the user. This helps users around the world view the same high-quality "
|
||||
. "content without slow loading times";
|
||||
$txt .= "<br>If you are using the CDN Storage, add this into your crontab <code>2 1 * * * php {$global['systemRootPath']}plugin/CDN/tools/moveMissingFiles.php</code>. "
|
||||
. "This command will daily check your files and free some space into your server";
|
||||
$help = "";
|
||||
return $txt . $help;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "CDN";
|
||||
}
|
||||
|
||||
public function getUUID()
|
||||
{
|
||||
return "CDN73225-3807-4167-ba81-0509dd280e06";
|
||||
}
|
||||
|
||||
public function getPluginVersion()
|
||||
{
|
||||
return "2.0";
|
||||
}
|
||||
|
||||
public function getEmptyDataObject()
|
||||
{
|
||||
global $global, $config;
|
||||
$obj = new stdClass();
|
||||
$obj->key = "";
|
||||
$obj->CDN = "";
|
||||
$obj->CDN_S3 = "";
|
||||
$obj->CDN_B2 = "";
|
||||
$obj->CDN_FTP = "";
|
||||
// this is a JSON with site_id + URL
|
||||
$obj->CDN_YPTStorage = ""; // array
|
||||
$obj->CDN_Live = "";
|
||||
// this is a JSON with servers_id + URL
|
||||
$obj->CDN_LiveServers = ""; // array
|
||||
$obj->enable_storage = false;
|
||||
$obj->storage_autoupload_new_videos = true;
|
||||
$obj->storage_users_can_choose_storage = true;
|
||||
$obj->storage_username = "";
|
||||
$obj->storage_password = "";
|
||||
$obj->storage_hostname = "";
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getVideosManagerListButton()
|
||||
{
|
||||
$btn = '';
|
||||
if (self::userCanMoveVideoStorage()) {
|
||||
$btn .= '<button type="button" class="btn btn-default btn-light btn-sm btn-xs btn-block " onclick="avideoModalIframeSmall(webSiteRootURL+\\\'plugin/CDN/Storage/syncVideo.php?videos_id=\'+ row.id +\'\\\');" ><i class="fas fa-project-diagram"></i> CDN Storage</button>';
|
||||
}
|
||||
return $btn;
|
||||
}
|
||||
|
||||
public function getPluginMenu()
|
||||
{
|
||||
global $global;
|
||||
$fileAPIName = $global['systemRootPath'] . 'plugin/CDN/pluginMenu.html';
|
||||
$content = file_get_contents($fileAPIName);
|
||||
$obj = $this->getDataObject();
|
||||
|
||||
$url = "https://youphp.tube/marketplace/CDN/iframe.php?hash={hash}";
|
||||
|
||||
$url = addQueryStringParameter($url, 'hash', $obj->key);
|
||||
$url = addQueryStringParameter($url, 'webSiteRootURL', $global['webSiteRootURL']);
|
||||
|
||||
$cdnMenu = str_replace('{url}', $url, $content);
|
||||
$storageMenu = '';
|
||||
if (self::userCanMoveVideoStorage()) {
|
||||
$fileStorageMenu = $global['systemRootPath'] . 'plugin/CDN/Storage/pluginMenu.html';
|
||||
$storageMenu = file_get_contents($fileStorageMenu);
|
||||
}
|
||||
return $cdnMenu.$storageMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $type enum(CDN, CDN_S3,CDN_B2,CDN_YPTStorage,CDN_Live,CDN_LiveServers)
|
||||
* @param type $id the ID of the URL in case the CDN is an array
|
||||
* @return boolean
|
||||
*/
|
||||
public static function getURL($type = 'CDN', $id = 0)
|
||||
{
|
||||
$obj = AVideoPlugin::getObjectData('CDN');
|
||||
|
||||
if (empty($obj->{$type})) {
|
||||
return false;
|
||||
}
|
||||
if (isIPPrivate(getDomain())) {
|
||||
_error_log('The CDN will not work under a private network $type=' . $type);
|
||||
return false;
|
||||
}
|
||||
$url = '';
|
||||
switch ($type) {
|
||||
case 'CDN':
|
||||
case 'CDN_S3':
|
||||
case 'CDN_B2':
|
||||
case 'CDN_FTP':
|
||||
case 'CDN_Live':
|
||||
$url = $obj->{$type};
|
||||
break;
|
||||
case 'CDN_LiveServers':
|
||||
case 'CDN_YPTStorage':
|
||||
if (!empty($id)) {
|
||||
$json = _json_decode($obj->{$type});
|
||||
//var_dump(!empty($json), is_object($json), is_array($json));//exit;
|
||||
if (!empty($json) && (is_object($json) || is_array($json))) {
|
||||
foreach ($json as $value) {
|
||||
if ($value->id == $id) {
|
||||
$url = $value->URLToCDN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//var_dump($url);exit;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($url) && isValidURL($url)) {
|
||||
return addLastSlash($url);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getCDN_S3URL()
|
||||
{
|
||||
$plugin = AVideoPlugin::getDataObjectIfEnabled('AWS_S3');
|
||||
$CDN_S3 = '';
|
||||
if (!empty($plugin)) {
|
||||
$region = trim($plugin->region);
|
||||
$bucket_name = trim($plugin->bucket_name);
|
||||
$endpoint = trim($plugin->endpoint);
|
||||
if (!empty($endpoint)) {
|
||||
$CDN_S3 = str_replace('https://', "https://{$bucket_name}.", $endpoint);
|
||||
} elseif (!empty($plugin->region)) {
|
||||
$CDN_S3 = "https://{$bucket_name}.s3-accesspoint.{$region}.amazonaws.com";
|
||||
}
|
||||
if (!empty($resp->CDN_S3)) {
|
||||
$CDN_S3 = addLastSlash($resp->CDN_S3);
|
||||
}
|
||||
}
|
||||
return $CDN_S3;
|
||||
}
|
||||
|
||||
public static function getCDN_B2URL()
|
||||
{
|
||||
$CDN_B2 = '';
|
||||
$plugin = AVideoPlugin::getDataObjectIfEnabled('Blackblaze_B2');
|
||||
if (!empty($plugin)) {
|
||||
$b2 = new Blackblaze_B2();
|
||||
$CDN_B2 = $b2->getEndpoint();
|
||||
if (!empty($resp->CDN_B2)) {
|
||||
$CDN_B2 = addLastSlash($resp->CDN_B2);
|
||||
}
|
||||
}
|
||||
return $CDN_B2;
|
||||
}
|
||||
|
||||
public static function getCDN_FTPURL()
|
||||
{
|
||||
$CDN_FTP = '';
|
||||
$plugin = AVideoPlugin::getDataObjectIfEnabled('CDN');
|
||||
if (!empty($plugin)) {
|
||||
$CDN_FTP = addLastSlash($plugin->endpoint);
|
||||
}
|
||||
return $CDN_FTP;
|
||||
}
|
||||
|
||||
public static function getVideoTags($videos_id)
|
||||
{
|
||||
global $global;
|
||||
if (empty($videos_id)) {
|
||||
return [];
|
||||
}
|
||||
if (!Video::canEdit($videos_id)) {
|
||||
return [];
|
||||
}
|
||||
$video = Video::getVideoLight($videos_id);
|
||||
$sites_id = $video['sites_id'];
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->label = 'Storage';
|
||||
$isMoving = CDNStorage::isMoving($videos_id);
|
||||
if ($isMoving) {
|
||||
$obj->type = "danger";
|
||||
$obj->text = '<i class="fas fa-sync fa-spin"></i> ' . __('Moving');
|
||||
} elseif (empty($sites_id)) {
|
||||
$obj->type = "success";
|
||||
$obj->text = '<i class="fas fa-map-marker-alt"></i> ' . __('Local');
|
||||
} else {
|
||||
$obj->type = "warning";
|
||||
$obj->text = "<i class=\"fas fa-project-diagram\"></i> " . __('Storage');
|
||||
}
|
||||
//var_dump($obj);exit;
|
||||
return [$obj];
|
||||
}
|
||||
|
||||
|
||||
public function onEncoderNotifyIsDone($videos_id)
|
||||
{
|
||||
return $this->processNewVideo($videos_id);
|
||||
}
|
||||
|
||||
public function onUploadIsDone($videos_id)
|
||||
{
|
||||
return $this->processNewVideo($videos_id);
|
||||
}
|
||||
|
||||
private function processNewVideo($videos_id)
|
||||
{
|
||||
$obj = AVideoPlugin::getDataObjectIfEnabled('CDN');
|
||||
if ($obj->enable_storage) {
|
||||
if ($obj->storage_autoupload_new_videos) {
|
||||
CDNStorage::moveLocalToRemote($videos_id, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function userCanMoveVideoStorage()
|
||||
{
|
||||
$obj = AVideoPlugin::getDataObjectIfEnabled('CDN');
|
||||
if (empty($obj->enable_storage)) {
|
||||
return false;
|
||||
}
|
||||
if (User::isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
if (!empty($obj->storage_users_can_choose_storage) && User::canUpload()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFooterCode()
|
||||
{
|
||||
global $global;
|
||||
if (self::userCanMoveVideoStorage()) {
|
||||
include $global['systemRootPath'] . 'plugin/CDN/Storage/footer.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1075,12 +1075,6 @@ class CDNStorage {
|
|||
$parts2 = explode('?', $parts1[1]);
|
||||
$relativeFilename = $parts2[0];
|
||||
$localFile = getVideosDir() . "{$relativeFilename}";
|
||||
$localFileLock = getVideosDir() . "{$relativeFilename}.lock";
|
||||
if(file_exists($localFileLock)){
|
||||
_error_log('convertCDNHLSVideoToDownlaod: download from CDN There is a process running for ' . $localFile);
|
||||
return false;
|
||||
}
|
||||
file_put_contents($localFileLock, time());
|
||||
//var_dump($localFile);exit;
|
||||
$returnURL = false;
|
||||
if (file_exists($localFile)) {
|
||||
|
@ -1105,20 +1099,7 @@ class CDNStorage {
|
|||
} else {
|
||||
//var_dump($localFile);exit;
|
||||
if (!file_exists($localFile)) {
|
||||
if ($format == 'mp3') {
|
||||
$command = get_ffmpeg() . " -i \"{$m3u8File}\" -c:a libmp3lame \"{$localFile}\"";
|
||||
} else {
|
||||
$command = get_ffmpeg() . " -i \"{$m3u8File}\" -c copy \"{$localFile}\"";
|
||||
}
|
||||
$progressFile = $localFile.'.log';
|
||||
$command .= " 1> \"{$progressFile}\" 2>&1";
|
||||
_error_log('convertCDNHLSVideoToDownlaod: download from CDN ' . $command);
|
||||
session_write_close();
|
||||
_mysql_close();
|
||||
exec($command, $output);
|
||||
_session_start();
|
||||
_mysql_connect();
|
||||
_error_log('convertCDNHLSVideoToDownlaod: download from CDN output: ' . json_encode($output));
|
||||
$progressFile = convertVideoFileWithFFMPEG($m3u8File, $localFile);
|
||||
}
|
||||
if (!file_exists($localFile)) {
|
||||
_error_log('convertCDNHLSVideoToDownlaod: download from CDN file not created ' . $localFile);
|
||||
|
@ -1135,7 +1116,6 @@ class CDNStorage {
|
|||
}
|
||||
}
|
||||
}
|
||||
unlink($localFileLock);
|
||||
return $returnURL;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,16 +15,8 @@ $videoHLSObj = AVideoPlugin::getDataObjectIfEnabled('VideoHLS');
|
|||
if (empty($videoHLSObj)) {
|
||||
forbiddenPage('VideoHLS plugin is required for that');
|
||||
}
|
||||
$downloadOptions = array();
|
||||
$cdnObj = AVideoPlugin::getDataObjectIfEnabled('CDN');
|
||||
if(!empty($cdnObj) && $cdnObj->enable_storage){
|
||||
if (!empty($videoHLSObj->saveMP4CopyOnCDNStorageToAllowDownload)) {
|
||||
$downloadOptions[] = VideoHLS::getCDNDownloadLink($videos_id, 'mp4');
|
||||
}
|
||||
if (!empty($videoHLSObj->saveMP3CopyOnCDNStorageToAllowDownload)) {
|
||||
$downloadOptions[] = VideoHLS::getCDNDownloadLink($videos_id, 'mp3');
|
||||
}
|
||||
}
|
||||
$downloadOptions = VideoHLS::getMP3ANDMP4DownloadLinks($videos_id);
|
||||
|
||||
if (empty($downloadOptions)) {
|
||||
forbiddenPage('All download options on VideoHLS plugin are disabled');
|
||||
}
|
||||
|
|
|
@ -1260,11 +1260,7 @@ function avideoAlert(title, msg, type) {
|
|||
if (typeof msg !== 'string') {
|
||||
return false;
|
||||
}
|
||||
if (msg !== msg.replace(/<\/?[^>]+(>|$)/g, "")) {//it has HTML
|
||||
avideoAlertHTMLText(title, msg, type);
|
||||
} else {
|
||||
swal(title, msg, type);
|
||||
}
|
||||
avideoAlertHTMLText(title, msg, type);
|
||||
}
|
||||
|
||||
function avideoAlertOnce(title, msg, type, uid) {
|
||||
|
@ -1370,6 +1366,7 @@ function avideoAlertAJAX(url) {
|
|||
}
|
||||
|
||||
function avideoAlertHTMLText(title, msg, type) {
|
||||
var isErrorOrWarning = (type=='error' || type=='warning');
|
||||
var span = document.createElement("span");
|
||||
span.innerHTML = msg;
|
||||
swal({
|
||||
|
@ -1377,7 +1374,8 @@ function avideoAlertHTMLText(title, msg, type) {
|
|||
content: span,
|
||||
icon: type,
|
||||
closeModal: true,
|
||||
buttons: type ? true : false,
|
||||
closeOnClickOutside: !isErrorOrWarning,
|
||||
buttons: isErrorOrWarning ? null : (empty(type)?false:true),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2208,7 +2206,8 @@ function goToURLOrAlertError(jsonURL, data) {
|
|||
}
|
||||
|
||||
function downloadURL(url, filename) {
|
||||
avideoToastInfo('Download start');
|
||||
filename = clean_name(filename)+'.'+clean_name(url.split(/[#?]/)[0].split('.').pop().trim());
|
||||
console.log('downloadURL start ', url, filename);
|
||||
var loaded = 0;
|
||||
var contentLength = 0;
|
||||
fetch(url)
|
||||
|
@ -2251,28 +2250,37 @@ function downloadURL(url, filename) {
|
|||
})
|
||||
.then(response => response.blob())
|
||||
.then(blob => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const urlFromBlob = window.URL.createObjectURL(blob);
|
||||
console.log('downloadURL', url, filename, blob);
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = url;
|
||||
a.href = urlFromBlob;
|
||||
// the filename you want
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
modal.hidePleaseWait();
|
||||
avideoToastSuccess('Download complete');
|
||||
avideoToastSuccess('Download complete '+filename);
|
||||
})
|
||||
.catch(function (err) {
|
||||
avideoAlertError('Error on download ');
|
||||
//console.log(err)
|
||||
//avideoAlertError('Error on download ');
|
||||
console.log(err);
|
||||
addQueryStringParameter(url, 'download', 1);
|
||||
addQueryStringParameter(url, 'title', filename);
|
||||
document.location = url;
|
||||
});
|
||||
}
|
||||
|
||||
var downloadURLOrAlertErrorInterval;
|
||||
function downloadURLOrAlertError(jsonURL, data, filename, FFMpegProgress) {
|
||||
if(empty(jsonURL)){
|
||||
console.log('downloadURLOrAlertError error empty jsonURL', jsonURL, data, filename, FFMpegProgress);
|
||||
return false;
|
||||
}
|
||||
modal.showPleaseWait();
|
||||
avideoToastInfo('Converting');
|
||||
console.log('downloadURLOrAlertError 1', jsonURL,FFMpegProgress);
|
||||
checkFFMPEGProgress(FFMpegProgress);
|
||||
$.ajax({
|
||||
url: jsonURL,
|
||||
|
@ -2678,7 +2686,7 @@ $(document).ready(function () {
|
|||
|
||||
setInterval(function () {
|
||||
setToolTips();
|
||||
}, 1000);
|
||||
}, 5000);
|
||||
/*
|
||||
$(".thumbsImage").on("mouseenter", function () {
|
||||
gifId = $(this).find(".thumbsGIF").attr('id');
|
||||
|
|
|
@ -180,14 +180,8 @@ $description = getSEODescription(emptyHTML($video['description']) ? $video['titl
|
|||
|
||||
$videoHLSObj = AVideoPlugin::getDataObjectIfEnabled('VideoHLS');
|
||||
if (!empty($videoHLSObj)) {
|
||||
if ($cdnStorageEnabled) {
|
||||
if (!empty($videoHLSObj->saveMP4CopyOnCDNStorageToAllowDownload)) {
|
||||
$filesToDownload[] = VideoHLS::getCDNDownloadLink($video['id'], 'mp4');
|
||||
}
|
||||
if (!empty($videoHLSObj->saveMP3CopyOnCDNStorageToAllowDownload)) {
|
||||
$filesToDownload[] = VideoHLS::getCDNDownloadLink($video['id'], 'mp3');
|
||||
}
|
||||
}
|
||||
$downloadOptions = VideoHLS::getMP3ANDMP4DownloadLinks($videos_id);
|
||||
$filesToDownload = array_merge($filesToDownload, $downloadOptions);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,104 +1,120 @@
|
|||
<?php
|
||||
global $global, $config;
|
||||
if (!isset($global['systemRootPath'])) {
|
||||
require_once '../videos/configuration.php';
|
||||
}
|
||||
|
||||
session_write_close();
|
||||
require_once $global['systemRootPath'] . 'objects/functions.php';
|
||||
require_once $global['systemRootPath'] . 'plugin/AVideoPlugin.php';
|
||||
|
||||
if (empty($_GET['file'])) {
|
||||
_error_log("XSENDFILE GET file not found ");
|
||||
die('GET file not found');
|
||||
}
|
||||
|
||||
$path_parts = pathinfo($_GET['file']);
|
||||
$file = $path_parts['basename'];
|
||||
//var_dump($_GET['file'], $path_parts, $file);exit;
|
||||
|
||||
if ($file == "test.mp4") {
|
||||
$path = "{$global['systemRootPath']}view/xsendfile.html";
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Type: text/html');
|
||||
header('Content-Length: ' . filesize($path));
|
||||
header("X-Sendfile: {$path}");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($file == "X-Sendfile.mp4") {
|
||||
$path = "{$global['systemRootPath']}plugin/SecureVideosDirectory/test.json";
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Type: application/json');
|
||||
header('Content-Length: ' . filesize($path));
|
||||
header("X-Sendfile: {$path}");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($file == "configuration.php") {
|
||||
_error_log("XSENDFILE Can't read this configuration ");
|
||||
forbiddenPage("Can't read this");
|
||||
}
|
||||
if(!empty($_REQUEST['cacheDownload'])){
|
||||
$file = preg_replace('/[^0-9a-z_\.]/i', '', $_GET['file']);
|
||||
$relativePath = "cache/download/";
|
||||
$path = getVideosDir().$relativePath.$file;
|
||||
$_GET['download'] = 1;
|
||||
_error_log("cacheDownload: $path");
|
||||
}else{
|
||||
$path = Video::getPathToFile($file);
|
||||
}
|
||||
if (file_exists($path)) {
|
||||
if (!empty($_GET['download'])) {
|
||||
if (empty($_REQUEST['cacheDownload']) && !CustomizeUser::canDownloadVideos()) {
|
||||
_error_log("downloadHLS: CustomizeUser::canDownloadVideos said NO");
|
||||
forbiddenPage("Can't download this");
|
||||
}
|
||||
if (!empty($_GET['title'])) {
|
||||
$quoted = sprintf('"%s"', addcslashes(basename($_GET['title']), '"\\'));
|
||||
} else {
|
||||
$quoted = sprintf('"%s"', addcslashes(basename($_GET['file']), '"\\'));
|
||||
}
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Disposition: attachment; filename=' . $quoted);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
}
|
||||
if (preg_match("/(mp4|webm|m3u8|mp3|ogg)/i", $path_parts['extension'])) {
|
||||
if (isAVideoEncoderOnSameDomain() || empty($_GET['ignoreXsendfilePreVideoPlay'])) {
|
||||
AVideoPlugin::xsendfilePreVideoPlay();
|
||||
}
|
||||
if (empty($advancedCustom->doNotUseXsendFile)) {
|
||||
//_error_log("X-Sendfile: {$path}");
|
||||
header("X-Sendfile: {$path}");
|
||||
} else {
|
||||
_error_log("Careful, we recommend you to use the X-Sendfile and it is disabled on AdvancedCustom plugin -> doNotUseXsendFile. You may have an error 'Allowed Memory Size Exhausted' if your video file is too big", AVideoLog::$WARNING);
|
||||
}
|
||||
} else {
|
||||
$advancedCustom->doNotUseXsendFile = true;
|
||||
}
|
||||
header("Content-type: " . mime_content_type($path));
|
||||
header('Content-Length: ' . filesize($path));
|
||||
if (!empty($advancedCustom->doNotUseXsendFile)) {
|
||||
ini_set('memory_limit', filesize($path) * 1.5);
|
||||
_error_log("Your XSEND File is not enabled, it may slow down your site, file = $path", AVideoLog::$WARNING);
|
||||
//echo url_get_contents($path);
|
||||
// stream the file
|
||||
$fp = fopen($path, 'rb');
|
||||
fpassthru($fp);
|
||||
}
|
||||
die();
|
||||
} else {
|
||||
_error_log("XSENDFILE ERROR: Not exists {$path}");
|
||||
}
|
||||
<?php
|
||||
global $global, $config;
|
||||
if (!isset($global['systemRootPath'])) {
|
||||
require_once '../videos/configuration.php';
|
||||
}
|
||||
|
||||
session_write_close();
|
||||
require_once $global['systemRootPath'] . 'objects/functions.php';
|
||||
require_once $global['systemRootPath'] . 'plugin/AVideoPlugin.php';
|
||||
|
||||
if (empty($_GET['file'])) {
|
||||
_error_log("XSENDFILE GET file not found ");
|
||||
die('GET file not found');
|
||||
}
|
||||
|
||||
if($_GET['file']=='index.mp4'){
|
||||
$url = parse_url($_SERVER["REQUEST_URI"]);
|
||||
$paths = Video::getPaths($url["path"]);
|
||||
$path = "{$paths['path']}index.mp4";
|
||||
$file = "{$paths["relative"]}index.mp4";
|
||||
$path_parts = pathinfo($file);
|
||||
//var_dump(__LINE__, $file, $path, $paths);
|
||||
}else{
|
||||
$path_parts = pathinfo($_GET['file']);
|
||||
$file = $path_parts['basename'];
|
||||
}
|
||||
//header('Content-Type: application/json');var_dump($path, $file, $paths, $url, Video::getPaths($redirectURI));exit;
|
||||
|
||||
if ($file == "test.mp4") {
|
||||
$path = "{$global['systemRootPath']}view/xsendfile.html";
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Type: text/html');
|
||||
header('Content-Length: ' . filesize($path));
|
||||
header("X-Sendfile: {$path}");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($file == "X-Sendfile.mp4") {
|
||||
$path = "{$global['systemRootPath']}plugin/SecureVideosDirectory/test.json";
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Type: application/json');
|
||||
header('Content-Length: ' . filesize($path));
|
||||
header("X-Sendfile: {$path}");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($file == "configuration.php") {
|
||||
_error_log("XSENDFILE Can't read this configuration ");
|
||||
forbiddenPage("Can't read this");
|
||||
}
|
||||
if(!empty($_REQUEST['cacheDownload'])){
|
||||
$file = preg_replace('/[^0-9a-z_\.]/i', '', $_GET['file']);
|
||||
$relativePath = "cache/download/";
|
||||
$path = getVideosDir().$relativePath.$file;
|
||||
$_GET['download'] = 1;
|
||||
_error_log("cacheDownload: $path");
|
||||
}else{
|
||||
$path = Video::getPathToFile($file);
|
||||
}
|
||||
//header('Content-Type: application/json');var_dump(__LINE__, $_SERVER["REQUEST_URI"], $file, $path);exit;
|
||||
//header('Content-Type: application/json');var_dump($advancedCustom->doNotUseXsendFile);
|
||||
if (file_exists($path)) {
|
||||
$filesize = filesize($path);
|
||||
if (!empty($_GET['download'])) {
|
||||
if (empty($_REQUEST['cacheDownload']) && !CustomizeUser::canDownloadVideos()) {
|
||||
_error_log("downloadHLS: CustomizeUser::canDownloadVideos said NO");
|
||||
forbiddenPage("Can't download this");
|
||||
}
|
||||
if (!empty($_GET['title'])) {
|
||||
$quoted = safeString($_GET['title'], true).".{$path_parts['extension']}";
|
||||
} else {
|
||||
$quoted = safeString(basename($_GET['file']), true).".{$path_parts['extension']}";
|
||||
}
|
||||
//header('Content-Type: application/json');var_dump($quoted);exit;
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Disposition: attachment; filename=' . $quoted);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
}
|
||||
if (preg_match("/(mp4|webm|m3u8|mp3|ogg)/i", $path_parts['extension'])) {
|
||||
if (isAVideoEncoderOnSameDomain() || empty($_GET['ignoreXsendfilePreVideoPlay'])) {
|
||||
AVideoPlugin::xsendfilePreVideoPlay();
|
||||
}
|
||||
if (empty($advancedCustom->doNotUseXsendFile)) {
|
||||
//_error_log("X-Sendfile: {$path}");
|
||||
header("X-Sendfile: {$path}");
|
||||
} else {
|
||||
_error_log("Careful, we recommend you to use the X-Sendfile and it is disabled on AdvancedCustom plugin -> doNotUseXsendFile. You may have an error 'Allowed Memory Size Exhausted' if your video file is too big", AVideoLog::$WARNING);
|
||||
}
|
||||
} else {
|
||||
$advancedCustom->doNotUseXsendFile = true;
|
||||
}
|
||||
header("Content-type: " . mime_content_type($path));
|
||||
header('Content-Length: ' . $filesize);
|
||||
//header("Content-Range: 0-".($filesize-1)."/".$filesize);
|
||||
_error_log("downloadHLS: filesize={$filesize} {$path}");
|
||||
//var_dump($advancedCustom->doNotUseXsendFile);exit;
|
||||
if (!empty($advancedCustom->doNotUseXsendFile)) {
|
||||
ini_set('memory_limit', filesize($path) * 1.5);
|
||||
_error_log("Your XSEND File is not enabled, it may slow down your site, file = $path", AVideoLog::$WARNING);
|
||||
//echo url_get_contents($path);
|
||||
// stream the file
|
||||
$fp = fopen($path, 'rb');
|
||||
fpassthru($fp);
|
||||
}
|
||||
die();
|
||||
} else {
|
||||
_error_log("XSENDFILE ERROR: Not exists {$path}");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue