1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

Add a caller timer

This commit is contained in:
DanieL 2022-07-23 09:26:57 -03:00
parent 2c07a7705e
commit dc9aec5bbe
9 changed files with 605 additions and 550 deletions

View file

@ -504,8 +504,9 @@ abstract class ObjectYPT implements ObjectInterface
if (empty($getCachesProcessed)) { if (empty($getCachesProcessed)) {
$getCachesProcessed = []; $getCachesProcessed = [];
} }
//if($name=='getVideosURL_V2video_220721204450_v21b7'){var_dump($name);exit;}
$cachefile = self::getCacheFileName($name, false); $cachefile = self::getCacheFileName($name, false);
//var_dump($cachefile);//exit; //if($name=='getVideosURL_V2video_220721204450_v21b7'){var_dump($cachefile);exit;}//exit;
self::setLastUsedCacheFile($cachefile); self::setLastUsedCacheFile($cachefile);
//_error_log('getCache: cachefile '.$cachefile); //_error_log('getCache: cachefile '.$cachefile);
if (!empty($_getCache[$name])) { if (!empty($_getCache[$name])) {

View file

@ -1332,7 +1332,9 @@ function getVideosURL_V2($fileName, $recreateCache = false) {
$TimeLog1 = "getVideosURL_V2($fileName) empty recreateCache"; $TimeLog1 = "getVideosURL_V2($fileName) empty recreateCache";
TimeLogStart($TimeLog1); 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)) { if (is_array($files)) {
//_error_log("getVideosURL_V2: do NOT recreate lifetime = {$lifetime}"); //_error_log("getVideosURL_V2: do NOT recreate lifetime = {$lifetime}");
$preg_match_url = addcslashes(getCDN(), "/") . "videos"; $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; global $global;
$relativePathOriginal = $relativePath; $relativePathOriginal = $relativePath;
$relativePath = getRelativePath($relativePath); $relativePath = getRelativePath($relativePath);
@ -2404,9 +2406,9 @@ function getImageTagIfExists($relativePath, $title='', $id='', $style='', $class
$wh = ''; $wh = '';
if (file_exists($file)) { if (file_exists($file)) {
// check if there is a thumbs // 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); $thumbs = str_replace('.jpg', '_thumbsV2.jpg', $file);
if(file_exists($thumbs)){ if (file_exists($thumbs)) {
$file = $thumbs; $file = $thumbs;
} }
} }
@ -2418,21 +2420,21 @@ function getImageTagIfExists($relativePath, $title='', $id='', $style='', $class
} else if (isValidURL($relativePathOriginal)) { } else if (isValidURL($relativePathOriginal)) {
$url = $relativePathOriginal; $url = $relativePathOriginal;
} else { } else {
return '<!-- invalid URL '.$relativePathOriginal.' -->'; return '<!-- invalid URL ' . $relativePathOriginal . ' -->';
} }
if(empty($title)){ if (empty($title)) {
$title = basename($relativePath); $title = basename($relativePath);
} }
$title = safeString($title); $title = safeString($title);
$img = "<img style=\"{$style}\" alt=\"{$title}\" title=\"{$title}\" id=\"{$id}\" class=\"{$class}\" {$wh} "; $img = "<img style=\"{$style}\" alt=\"{$title}\" title=\"{$title}\" id=\"{$id}\" class=\"{$class}\" {$wh} ";
if($lazyLoad){ if ($lazyLoad) {
if(is_string($lazyLoad)){ if (is_string($lazyLoad)) {
$loading = getURL($lazyLoad); $loading = getURL($lazyLoad);
}else{ } else {
$loading = getURL('view/img/loading-gif.png'); $loading = getURL('view/img/loading-gif.png');
} }
$img .= " src=\"{$loading}\" data-src=\"{$url}\" "; $img .= " src=\"{$loading}\" data-src=\"{$url}\" ";
}else{ } else {
$img .= " src=\"{$url}\" "; $img .= " src=\"{$url}\" ";
} }
$img .= "/>"; $img .= "/>";
@ -2440,47 +2442,47 @@ function getImageTagIfExists($relativePath, $title='', $id='', $style='', $class
return $img; return $img;
} }
function createWebPIfNotExists($path){ function createWebPIfNotExists($path) {
if(version_compare(PHP_VERSION, '8.0.0') < 0 || !file_exists($path)){ if (version_compare(PHP_VERSION, '8.0.0') < 0 || !file_exists($path)) {
return $path; return $path;
} }
$extension = pathinfo($path, PATHINFO_EXTENSION); $extension = pathinfo($path, PATHINFO_EXTENSION);
if($extension!=='jpg'){ if ($extension !== 'jpg') {
return $path; return $path;
} }
$nextGenPath = str_replace('.jpg', '_jpg.webp', $path); $nextGenPath = str_replace('.jpg', '_jpg.webp', $path);
if(!file_exists($nextGenPath)){ if (!file_exists($nextGenPath)) {
convertImage($path, $nextGenPath, 70); convertImage($path, $nextGenPath, 70);
} }
return $nextGenPath; return $nextGenPath;
} }
function getVideoImagewithHoverAnimation($relativePath, $relativePathHoverAnimation='', $title=''){ function getVideoImagewithHoverAnimation($relativePath, $relativePathHoverAnimation = '', $title = '') {
$id = uniqid(); $id = uniqid();
$img = getImageTagIfExists($relativePath, $title, "thumbsJPG{$id}", '', 'thumbsJPG img img-responsive').PHP_EOL; $img = getImageTagIfExists($relativePath, $title, "thumbsJPG{$id}", '', 'thumbsJPG img img-responsive') . PHP_EOL;
if(!empty($relativePathHoverAnimation) && empty($_REQUEST['noImgGif'])){ 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($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; global $global;
$relativePath = ''; $relativePath = '';
$parts = explode('view/img/', $path); $parts = explode('view/img/', $path);
if(!empty($parts[1])){ if (!empty($parts[1])) {
$relativePath = 'view/img/'.$parts[1]; $relativePath = 'view/img/' . $parts[1];
} }
if(empty($relativePath)){ if (empty($relativePath)) {
$parts = explode('videos/', $path); $parts = explode('videos/', $path);
if(!empty($parts[1])){ if (!empty($parts[1])) {
$relativePath = 'videos/'.$parts[1]; $relativePath = 'videos/' . $parts[1];
} }
} }
if(empty($relativePath)){ if (empty($relativePath)) {
$relativePath = $path; $relativePath = $path;
} }
$parts2 = explode('?', $relativePath); $parts2 = explode('?', $relativePath);
@ -3495,7 +3497,7 @@ function rrmdir($dir) {
} }
if (rmdir($dir)) { if (rmdir($dir)) {
return true; return true;
} else if(is_dir($dir)){ } else if (is_dir($dir)) {
_error_log('rrmdir: could not delete folder ' . $dir); _error_log('rrmdir: could not delete folder ' . $dir);
return false; return false;
} }
@ -5168,16 +5170,20 @@ function isValidURLOrPath($str, $insideCacheOrTmpDirOnly = true) {
_error_log('isValidURLOrPath return false (is php file) ' . $str); _error_log('isValidURLOrPath return false (is php file) ' . $str);
return false; return false;
} }
$cacheDir = "{$global['systemRootPath']}videos/"; if (
if (str_starts_with($absolutePath, $absolutePathTmp) || str_starts_with($absolutePath, '/var/www/') || str_starts_with($absolutePath, $absolutePathCache)) { 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; return true;
} }
} else { } else {
return true; return true;
} }
_error_log('isValidURLOrPath return false not valid absolute path 1 ' . $absolutePath); //_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 2 ' . $absolutePathTmp);
_error_log('isValidURLOrPath return false not valid absolute path 3 ' . $absolutePathCache); //_error_log('isValidURLOrPath return false not valid absolute path 3 ' . $absolutePathCache);
} }
//_error_log('isValidURLOrPath return false '.$str); //_error_log('isValidURLOrPath return false '.$str);
return false; return false;
@ -5843,6 +5849,7 @@ function _json_encode($object) {
} }
function _json_decode($object) { function _json_decode($object) {
global $global;
if (empty($object)) { if (empty($object)) {
return false; return false;
} }
@ -6696,69 +6703,6 @@ function playHLSasMP4($filepath) {
exit; 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 = "") { function getSocialModal($videos_id, $url = "", $title = "") {
global $global; global $global;
$video['id'] = $videos_id; $video['id'] = $videos_id;
@ -6886,6 +6830,123 @@ function get_ffmpeg($ignoreGPU = false) {
return $ffmpeg . $complement; 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() { function get_php() {
global $global; global $global;
$php = 'php '; $php = 'php ';
@ -8020,20 +8081,21 @@ function getCDNOrURL($url, $type = 'CDN', $id = 0) {
function replaceCDNIfNeed($url, $type = 'CDN', $id = 0) { function replaceCDNIfNeed($url, $type = 'CDN', $id = 0) {
$cdn = getCDN($type, $id); $cdn = getCDN($type, $id);
if(!empty($_GET['debug'])){ if (!empty($_GET['debug'])) {
$obj = AVideoPlugin::getDataObject('Blackblaze_B2'); $obj = AVideoPlugin::getDataObject('Blackblaze_B2');
var_dump($url, $type, $id, $cdn, $obj->CDN_Link);exit; var_dump($url, $type, $id, $cdn, $obj->CDN_Link);
exit;
} }
if (empty($cdn)) { if (empty($cdn)) {
if($type == 'CDN_B2'){ if ($type == 'CDN_B2') {
$obj = AVideoPlugin::getDataObject('Blackblaze_B2'); $obj = AVideoPlugin::getDataObject('Blackblaze_B2');
if(isValidURL($obj->CDN_Link)){ if (isValidURL($obj->CDN_Link)) {
$basename = basename($url); $basename = basename($url);
return addLastSlash($obj->CDN_Link).$basename; return addLastSlash($obj->CDN_Link) . $basename;
} }
}else if($type == 'CDN_S3'){ } else if ($type == 'CDN_S3') {
$obj = AVideoPlugin::getDataObject('AWS_S3'); $obj = AVideoPlugin::getDataObject('AWS_S3');
if(isValidURL($obj->CDN_Link)){ if (isValidURL($obj->CDN_Link)) {
$cdn = $obj->CDN_Link; $cdn = $obj->CDN_Link;
} }
} }
@ -9071,9 +9133,9 @@ function deleteInvalidImage($filepath) {
* @param string $text * @param string $text
* @return string * @return string
*/ */
function addTwitterJS($text){ function addTwitterJS($text) {
if(preg_match('/href=.+twitter.com.+ref_src=.+/', $text)){ if (preg_match('/href=.+twitter.com.+ref_src=.+/', $text)) {
if(!preg_match('/platform.twitter.com.widgets.js/', $text)){ if (!preg_match('/platform.twitter.com.widgets.js/', $text)) {
$text .= '<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>'; $text .= '<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>';
} }
} }

View file

@ -3349,6 +3349,7 @@ if (!class_exists('Video')) {
return $__getPaths[$videoFilename]; return $__getPaths[$videoFilename];
} }
$cleanVideoFilename = self::getCleanFilenameFromFile($videoFilename); $cleanVideoFilename = self::getCleanFilenameFromFile($videoFilename);
//var_dump($videoFilename, $path,$cleanVideoFilename);
$videosDir = self::getStoragePath(); $videosDir = self::getStoragePath();
$path = addLastSlash("{$videosDir}{$cleanVideoFilename}"); $path = addLastSlash("{$videosDir}{$cleanVideoFilename}");
@ -3371,11 +3372,16 @@ if (!class_exists('Video')) {
$videosDir = self::getStoragePath(); $videosDir = self::getStoragePath();
$videoFilename = str_replace($videosDir, '', $videoFilename); $videoFilename = str_replace($videosDir, '', $videoFilename);
$paths = Video::getPaths($videoFilename, $createDir); $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'], DIRECTORY_SEPARATOR);
$paths['path'] = rtrim($paths['path'], '/');
$videoFilename = str_replace($paths['relative'], '', $videoFilename);
$videoFilename = str_replace($paths['filename'], '', $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) { public static function getURLToFile($videoFilename, $createDir = false) {
@ -3511,9 +3517,11 @@ if (!class_exists('Video')) {
} }
$filename = fixPath($filename); $filename = fixPath($filename);
$filename = str_replace(getVideosDir(), '', $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]; return $matches[1];
} }
$search = ['_Low', '_SD', '_HD', '_thumbsV2', '_thumbsSmallV2', '_thumbsSprit', '_roku', '_portrait', '_portrait_thumbsV2', '_portrait_thumbsSmallV2', '_thumbsV2_jpg', '_spectrum', '_tvg', '.notfound']; $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'])) { if (!empty($global['langs_codes_values_withdot']) && is_array($global['langs_codes_values_withdot'])) {

View file

@ -69,12 +69,6 @@ class CDN extends PluginAbstract
public function getVideosManagerListButton() public function getVideosManagerListButton()
{ {
$btn = ''; $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()) { 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>'; $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>';
} }

View file

@ -1075,12 +1075,6 @@ class CDNStorage {
$parts2 = explode('?', $parts1[1]); $parts2 = explode('?', $parts1[1]);
$relativeFilename = $parts2[0]; $relativeFilename = $parts2[0];
$localFile = getVideosDir() . "{$relativeFilename}"; $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; //var_dump($localFile);exit;
$returnURL = false; $returnURL = false;
if (file_exists($localFile)) { if (file_exists($localFile)) {
@ -1105,20 +1099,7 @@ class CDNStorage {
} else { } else {
//var_dump($localFile);exit; //var_dump($localFile);exit;
if (!file_exists($localFile)) { if (!file_exists($localFile)) {
if ($format == 'mp3') { $progressFile = convertVideoFileWithFFMPEG($m3u8File, $localFile);
$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));
} }
if (!file_exists($localFile)) { if (!file_exists($localFile)) {
_error_log('convertCDNHLSVideoToDownlaod: download from CDN file not created ' . $localFile); _error_log('convertCDNHLSVideoToDownlaod: download from CDN file not created ' . $localFile);
@ -1135,7 +1116,6 @@ class CDNStorage {
} }
} }
} }
unlink($localFileLock);
return $returnURL; return $returnURL;
} }

View file

@ -15,16 +15,8 @@ $videoHLSObj = AVideoPlugin::getDataObjectIfEnabled('VideoHLS');
if (empty($videoHLSObj)) { if (empty($videoHLSObj)) {
forbiddenPage('VideoHLS plugin is required for that'); forbiddenPage('VideoHLS plugin is required for that');
} }
$downloadOptions = array(); $downloadOptions = VideoHLS::getMP3ANDMP4DownloadLinks($videos_id);
$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');
}
}
if (empty($downloadOptions)) { if (empty($downloadOptions)) {
forbiddenPage('All download options on VideoHLS plugin are disabled'); forbiddenPage('All download options on VideoHLS plugin are disabled');
} }

View file

@ -1260,11 +1260,7 @@ function avideoAlert(title, msg, type) {
if (typeof msg !== 'string') { if (typeof msg !== 'string') {
return false; return false;
} }
if (msg !== msg.replace(/<\/?[^>]+(>|$)/g, "")) {//it has HTML
avideoAlertHTMLText(title, msg, type); avideoAlertHTMLText(title, msg, type);
} else {
swal(title, msg, type);
}
} }
function avideoAlertOnce(title, msg, type, uid) { function avideoAlertOnce(title, msg, type, uid) {
@ -1370,6 +1366,7 @@ function avideoAlertAJAX(url) {
} }
function avideoAlertHTMLText(title, msg, type) { function avideoAlertHTMLText(title, msg, type) {
var isErrorOrWarning = (type=='error' || type=='warning');
var span = document.createElement("span"); var span = document.createElement("span");
span.innerHTML = msg; span.innerHTML = msg;
swal({ swal({
@ -1377,7 +1374,8 @@ function avideoAlertHTMLText(title, msg, type) {
content: span, content: span,
icon: type, icon: type,
closeModal: true, 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) { 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 loaded = 0;
var contentLength = 0; var contentLength = 0;
fetch(url) fetch(url)
@ -2251,28 +2250,37 @@ function downloadURL(url, filename) {
}) })
.then(response => response.blob()) .then(response => response.blob())
.then(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'); const a = document.createElement('a');
a.style.display = 'none'; a.style.display = 'none';
a.href = url; a.href = urlFromBlob;
// the filename you want // the filename you want
a.download = filename; a.download = filename;
document.body.appendChild(a); document.body.appendChild(a);
a.click(); a.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
modal.hidePleaseWait(); modal.hidePleaseWait();
avideoToastSuccess('Download complete'); avideoToastSuccess('Download complete '+filename);
}) })
.catch(function (err) { .catch(function (err) {
avideoAlertError('Error on download '); //avideoAlertError('Error on download ');
//console.log(err) console.log(err);
addQueryStringParameter(url, 'download', 1);
addQueryStringParameter(url, 'title', filename);
document.location = url;
}); });
} }
var downloadURLOrAlertErrorInterval; var downloadURLOrAlertErrorInterval;
function downloadURLOrAlertError(jsonURL, data, filename, FFMpegProgress) { function downloadURLOrAlertError(jsonURL, data, filename, FFMpegProgress) {
if(empty(jsonURL)){
console.log('downloadURLOrAlertError error empty jsonURL', jsonURL, data, filename, FFMpegProgress);
return false;
}
modal.showPleaseWait(); modal.showPleaseWait();
avideoToastInfo('Converting'); avideoToastInfo('Converting');
console.log('downloadURLOrAlertError 1', jsonURL,FFMpegProgress);
checkFFMPEGProgress(FFMpegProgress); checkFFMPEGProgress(FFMpegProgress);
$.ajax({ $.ajax({
url: jsonURL, url: jsonURL,
@ -2678,7 +2686,7 @@ $(document).ready(function () {
setInterval(function () { setInterval(function () {
setToolTips(); setToolTips();
}, 1000); }, 5000);
/* /*
$(".thumbsImage").on("mouseenter", function () { $(".thumbsImage").on("mouseenter", function () {
gifId = $(this).find(".thumbsGIF").attr('id'); gifId = $(this).find(".thumbsGIF").attr('id');

View file

@ -180,14 +180,8 @@ $description = getSEODescription(emptyHTML($video['description']) ? $video['titl
$videoHLSObj = AVideoPlugin::getDataObjectIfEnabled('VideoHLS'); $videoHLSObj = AVideoPlugin::getDataObjectIfEnabled('VideoHLS');
if (!empty($videoHLSObj)) { if (!empty($videoHLSObj)) {
if ($cdnStorageEnabled) { $downloadOptions = VideoHLS::getMP3ANDMP4DownloadLinks($videos_id);
if (!empty($videoHLSObj->saveMP4CopyOnCDNStorageToAllowDownload)) { $filesToDownload = array_merge($filesToDownload, $downloadOptions);
$filesToDownload[] = VideoHLS::getCDNDownloadLink($video['id'], 'mp4');
}
if (!empty($videoHLSObj->saveMP3CopyOnCDNStorageToAllowDownload)) {
$filesToDownload[] = VideoHLS::getCDNDownloadLink($video['id'], 'mp3');
}
}
} }

View file

@ -13,9 +13,18 @@ if (empty($_GET['file'])) {
die('GET file not found'); die('GET file not found');
} }
$path_parts = pathinfo($_GET['file']); if($_GET['file']=='index.mp4'){
$file = $path_parts['basename']; $url = parse_url($_SERVER["REQUEST_URI"]);
//var_dump($_GET['file'], $path_parts, $file);exit; $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") { if ($file == "test.mp4") {
$path = "{$global['systemRootPath']}view/xsendfile.html"; $path = "{$global['systemRootPath']}view/xsendfile.html";
@ -56,17 +65,21 @@ if(!empty($_REQUEST['cacheDownload'])){
}else{ }else{
$path = Video::getPathToFile($file); $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)) { if (file_exists($path)) {
$filesize = filesize($path);
if (!empty($_GET['download'])) { if (!empty($_GET['download'])) {
if (empty($_REQUEST['cacheDownload']) && !CustomizeUser::canDownloadVideos()) { if (empty($_REQUEST['cacheDownload']) && !CustomizeUser::canDownloadVideos()) {
_error_log("downloadHLS: CustomizeUser::canDownloadVideos said NO"); _error_log("downloadHLS: CustomizeUser::canDownloadVideos said NO");
forbiddenPage("Can't download this"); forbiddenPage("Can't download this");
} }
if (!empty($_GET['title'])) { if (!empty($_GET['title'])) {
$quoted = sprintf('"%s"', addcslashes(basename($_GET['title']), '"\\')); $quoted = safeString($_GET['title'], true).".{$path_parts['extension']}";
} else { } else {
$quoted = sprintf('"%s"', addcslashes(basename($_GET['file']), '"\\')); $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-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . $quoted); header('Content-Disposition: attachment; filename=' . $quoted);
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
@ -89,7 +102,10 @@ if (file_exists($path)) {
$advancedCustom->doNotUseXsendFile = true; $advancedCustom->doNotUseXsendFile = true;
} }
header("Content-type: " . mime_content_type($path)); header("Content-type: " . mime_content_type($path));
header('Content-Length: ' . filesize($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)) { if (!empty($advancedCustom->doNotUseXsendFile)) {
ini_set('memory_limit', filesize($path) * 1.5); 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); _error_log("Your XSEND File is not enabled, it may slow down your site, file = $path", AVideoLog::$WARNING);