1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00
daniel 2018-03-07 10:43:20 -03:00
parent 3b3c32b535
commit 58b86c39cf
5 changed files with 107 additions and 79 deletions

View file

@ -616,7 +616,15 @@ function getimgsize($file_src){
$name = "getimgsize_". md5($file_src); $name = "getimgsize_". md5($file_src);
$cached = ObjectYPT::getCache($name, 86400);//one day $cached = ObjectYPT::getCache($name, 86400);//one day
if(!empty($cached)){ if(!empty($cached)){
return (Array) $cached; $c = (Array) $cached;
$size = array();
foreach ($c as $key => $value) {
if(preg_match("/^[0-9]+$/", $key)){
$key = intval($key);
}
$size[$key] = $value;
}
return $size;
} }
$size = @getimagesize($file_src); $size = @getimagesize($file_src);
@ -701,4 +709,30 @@ function im_resize($file_src, $file_dest, $wd, $hd) {
@chmod($file_dest, 0666); @chmod($file_dest, 0666);
return true; return true;
}
function decideMoveUploadedToVideos($tmp_name, $filename){
global $global;
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
if (!empty($aws_s3)) {
$aws_s3->move_uploaded_file($tmp_name, $filename);
} else {
if (!move_uploaded_file($tmp_name, "{$global['systemRootPath']}videos/{$filename}")) {
$obj->msg = "Error on move_uploaded_file({$tmp_name}, {$global['systemRootPath']}videos/{$filename})";
die(json_encode($obj));
}
}
}
function decideFile_put_contentsToVideos($tmp_name, $filename){
global $global;
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
if (!empty($aws_s3)) {
$aws_s3->move_uploaded_file($tmp_name, $filename);
} else {
if (!move_uploaded_file($tmp_name, "{$global['systemRootPath']}videos/{$filename}")) {
$obj->msg = "Error on move_uploaded_file({$tmp_name}, {$global['systemRootPath']}videos/{$filename})";
die(json_encode($obj));
}
}
} }

View file

@ -668,23 +668,39 @@ class Video {
if (empty($resp)) { if (empty($resp)) {
die('Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); die('Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
} else { } else {
$path = self::getStoragePath(); $this->removeFiles($video['filename']);
foreach (self::$types as $value) { $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
$file = "{$path}original_{$video['filename']}"; if(!empty($aws_s3)){
if (file_exists($file)) { $aws_s3->removeFiles($video['filename']);
@unlink($file);
}
// Streamlined for less coding space.
$files = glob("{$path}{$video['filename']}.*");
foreach ($files as $file) {
if (file_exists($file)) {
@unlink($file);
}
}
} }
} }
return $resp; return $resp;
} }
private function removeFiles($filename){
if(empty($filename)){
return false;
}
global $global;
$file = "{$global['systemRootPath']}videos/original_{$filename}";
$this->removeFilePath($file);
$files = "{$global['systemRootPath']}videos/{$filename}";
$this->removeFilePath($files);
}
private function removeFilePath($filePath){
if(empty($filePath)){
return false;
}
// Streamlined for less coding space.
$files = glob("{$filePath}.*");
foreach ($files as $file) {
if (file_exists($file)) {
@unlink($file);
}
}
}
function setDescription($description) { function setDescription($description) {
$this->description = $description; $this->description = $description;
@ -752,12 +768,12 @@ class Video {
$getID3 = new getID3; $getID3 = new getID3;
// Analyze file and store returned data in $ThisFileInfo // Analyze file and store returned data in $ThisFileInfo
$ThisFileInfo = $getID3->analyze($file); $ThisFileInfo = $getID3->analyze($file);
return static::getCleanDuration($ThisFileInfo['playtime_string']); return static::getCleanDuration(@$ThisFileInfo['playtime_string']);
} }
function updateDurationIfNeed($fileExtension = ".mp4") { function updateDurationIfNeed($fileExtension = ".mp4") {
global $global; global $global;
$source = self::getSourceFile($this->filename, $fileExtension); $source = self::getSourceFile($this->filename, $fileExtension, true);
$file = $source['path']; $file = $source['path'];
if (!empty($this->id) && $this->duration == "EE:EE:EE" && file_exists($file)) { if (!empty($this->id) && $this->duration == "EE:EE:EE" && file_exists($file)) {
@ -1193,7 +1209,7 @@ class Video {
* @param type $type * @param type $type
* @return type .jpg .gif _thumbs.jpg _Low.mp4 _SD.mp4 _HD.mp4 * @return type .jpg .gif _thumbs.jpg _Low.mp4 _SD.mp4 _HD.mp4
*/ */
static function getSourceFile($filename, $type=".jpg") { static function getSourceFile($filename, $type=".jpg", $includeS3 = false) {
global $global; global $global;
$name = "getSourceFile_{$filename}{$type}_"; $name = "getSourceFile_{$filename}{$type}_";
$cached = ObjectYPT::getCache($name, 86400);//one day $cached = ObjectYPT::getCache($name, 86400);//one day
@ -1203,10 +1219,13 @@ class Video {
$source = array(); $source = array();
$source['path'] = "{$global['systemRootPath']}videos/{$filename}{$type}"; $source['path'] = "{$global['systemRootPath']}videos/{$filename}{$type}";
$source['url'] = "{$global['webSiteRootURL']}videos/{$filename}{$type}"; $source['url'] = "{$global['webSiteRootURL']}videos/{$filename}{$type}";
if (!file_exists($source['path']) || filesize($source['path']) < 1024) { /* need it because getDurationFromFile*/
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); if($includeS3){
if (!empty($aws_s3)) { if (!file_exists($source['path']) || filesize($source['path']) < 1024) {
$source = $aws_s3->getAddress("{$filename}{$type}"); $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
if (!empty($aws_s3)) {
$source = $aws_s3->getAddress("{$filename}{$type}");
}
} }
} }
ObjectYPT::setCache($name, $source); ObjectYPT::setCache($name, $source);
@ -1234,18 +1253,18 @@ class Video {
$gifSource = self::getSourceFile($filename, ".gif"); $gifSource = self::getSourceFile($filename, ".gif");
$jpegSource = self::getSourceFile($filename, ".jpg"); $jpegSource = self::getSourceFile($filename, ".jpg");
$thumbsSource = self::getSourceFile($filename, "_thumbs.jpg"); $thumbsSource = self::getSourceFile($filename, "_thumbs.jpg");
$obj->poster = ""; $obj->poster = $jpegSource['url'];
$obj->thumbsGif = ""; $obj->thumbsGif = $gifSource['url'];
$obj->thumbsJpg = ""; $obj->thumbsJpg = $thumbsSource['url'];
if ($type !== "audio") { if ($type !== "audio") {
if (file_exists($gifSource['path'])) { if (file_exists($gifSource['path'])) {
$obj->thumbsGif = $gifSource['url']; $obj->thumbsGif = $gifSource['url'];
} }
if (file_exists($jpegSource['path']) && filesize($jpegSource['path']) > 1024) { if (file_exists($jpegSource['path'])) {
$obj->poster = $jpegSource['url']; $obj->poster = $jpegSource['url'];
$obj->thumbsJpg = $thumbsSource['url']; $obj->thumbsJpg = $thumbsSource['url'];
// create thumbs // create thumbs
if (!file_exists($thumbsSource['path'])) { if (!file_exists($thumbsSource['path']) && filesize($jpegSource['path']) > 1024) {
im_resize($jpegSource['path'], $thumbsSource['path'], 250, 140); im_resize($jpegSource['path'], $thumbsSource['path'], 250, 140);
} }
} else { } else {

View file

@ -66,53 +66,30 @@ if (empty($videoFileName)) {
$destination_local = "{$global['systemRootPath']}videos/{$videoFileName}"; $destination_local = "{$global['systemRootPath']}videos/{$videoFileName}";
// get video file from encoder // get video file from encoder
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
if(empty($aws_s3)){
$destination = $destination_local;
error_log("Using Local Storage: {$destination}");
}else{
$address = $aws_s3->getAddress($filename);
$destination = "{$address['path']}";
error_log("Using AWS Storage: {$destination}");
}
if (!empty($_FILES['video']['tmp_name'])) { if (!empty($_FILES['video']['tmp_name'])) {
$resolution = ""; $resolution = "";
if (!empty($_POST['resolution'])) { if (!empty($_POST['resolution'])) {
$resolution = "_{$_POST['resolution']}"; $resolution = "_{$_POST['resolution']}";
} }
$destination_resolution_file = "{$destination}{$resolution}.{$_POST['format']}"; $filename = "{$videoFileName}{$resolution}.{$_POST['format']}";
if (!move_uploaded_file($_FILES['video']['tmp_name'], $destination_resolution_file)) { decideMoveUploadedToVideos($_FILES['video']['tmp_name'], $filename);
$obj->msg = print_r(sprintf(__("Could not move video file [%s] => [%s %s %s]"), $_FILES['video']['tmp_name'], $destination, $_POST['format'], $resolution), true);
error_log($obj->msg);
die(json_encode($obj));
}
if(!empty($aws_s3)){
file_put_contents( "{$destination_local}{$resolution}.{$_POST['format']}" , "Dummy File for $destination_resolution_file " );
}
} else { } else {
// set encoding // set encoding
$video->setStatus('e'); $video->setStatus('e');
} }
if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination}.jpg")) { if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination_local}.jpg")) {
if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$destination}.jpg")) { if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$destination_local}.jpg")) {
$obj->msg = print_r(sprintf(__("Could not move image file [%s.jpg]"), $destination), true); $obj->msg = print_r(sprintf(__("Could not move image file [%s.jpg]"), $destination_local), true);
error_log($obj->msg); error_log($obj->msg);
die(json_encode($obj)); die(json_encode($obj));
} }
if(!empty($aws_s3)){ }
file_put_contents( "{$destination_local}.jpg" , "Dummy File" ); if (!empty($_FILES['gifimage']['tmp_name']) && !file_exists("{$destination_local}.gif")) {
} if (!move_uploaded_file($_FILES['gifimage']['tmp_name'], "{$destination_local}.gif")) {
} $obj->msg = print_r(sprintf(__("Could not move gif image file [%s.gif]"), $destination_local), true);
if (!empty($_FILES['gifimage']['tmp_name']) && !file_exists("{$destination}.gif")) {
if (!move_uploaded_file($_FILES['gifimage']['tmp_name'], "{$destination}.gif")) {
$obj->msg = print_r(sprintf(__("Could not move gif image file [%s.gif]"), $destination), true);
error_log($obj->msg); error_log($obj->msg);
die(json_encode($obj)); die(json_encode($obj));
} }
if(!empty($aws_s3)){
file_put_contents( "{$destination_local}.gif" , "Dummy File" );
}
} }
$video_id = $video->save(); $video_id = $video->save();
$video->updateDurationIfNeed(); $video->updateDurationIfNeed();

View file

@ -162,6 +162,11 @@ class YouPHPTubePlugin{
return !empty(Plugin::getEnabled($uuid)); return !empty(Plugin::getEnabled($uuid));
} }
static function isEnabledByName($name){
$p = static::loadPluginIfEnabled($name);
return !empty($p);
}
static function getLogin(){ static function getLogin(){
$plugins = Plugin::getAllEnabled(); $plugins = Plugin::getAllEnabled();
$logins = array(); $logins = array();

View file

@ -1,4 +1,5 @@
<?php <?php
$configFile = '../../videos/configuration.php'; $configFile = '../../videos/configuration.php';
if (!file_exists($configFile)) { if (!file_exists($configFile)) {
$configFile = '../videos/configuration.php'; $configFile = '../videos/configuration.php';
@ -17,7 +18,7 @@ $allowed = array('mp4');
if (isset($_FILES['upl']) && $_FILES['upl']['error'] == 0) { if (isset($_FILES['upl']) && $_FILES['upl']['error'] == 0) {
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION); $extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if (!in_array(strtolower($extension), $allowed)) { if (!in_array(strtolower($extension), $allowed)) {
$obj->msg = "File extension error [{$_FILES['upl']['name']}], we allow only (". implode(",", $allowed) . ")"; $obj->msg = "File extension error [{$_FILES['upl']['name']}], we allow only (" . implode(",", $allowed) . ")";
die(json_encode($obj)); die(json_encode($obj));
} }
//var_dump($extension, $type);exit; //var_dump($extension, $type);exit;
@ -26,37 +27,29 @@ if (isset($_FILES['upl']) && $_FILES['upl']['error'] == 0) {
$path_parts = pathinfo($_FILES['upl']['name']); $path_parts = pathinfo($_FILES['upl']['name']);
$mainName = preg_replace("/[^A-Za-z0-9]/", "", cleanString($path_parts['filename'])); $mainName = preg_replace("/[^A-Za-z0-9]/", "", cleanString($path_parts['filename']));
$filename = uniqid($mainName . "_", true); $filename = uniqid($mainName . "_", true);
$video = new Video(substr(preg_replace("/_+/", " ", $_FILES['upl']['name']),0,-4), $filename, @$_FILES['upl']['videoId']); $video = new Video(substr(preg_replace("/_+/", " ", $_FILES['upl']['name']), 0, -4), $filename, @$_FILES['upl']['videoId']);
$video->setDuration($duration); $video->setDuration($duration);
$video->setType("video"); $video->setType("video");
$video->setStatus('a'); $video->setStatus('a');
$id = $video->save(); $id = $video->save();
/** /**
* This is when is using in a non uploaded movie * This is when is using in a non uploaded movie
*/ */
$path = Video::getStoragePath();
if (!move_uploaded_file($_FILES['upl']['tmp_name'], $path . $filename.".mp4")) {
$obj->msg = "Error on move_uploaded_file(" . $_FILES['upl']['tmp_name'] . ", " . $path . $filename.".mp4)";
die(json_encode($obj));
}
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3'); $aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
if(!empty($aws_s3)){ $tmp_name = $_FILES['upl']['tmp_name'];
file_put_contents( "{$global['systemRootPath']}videos/{$filename}.mp4" , "Dummy File" ); $filenameMP4 = $filename . ".mp4";
} decideMoveUploadedToVideos($tmp_name, $filenameMP4);
if (YouPHPTubePlugin::isEnabled("996c9afb-b90e-40ca-90cb-934856180bb9")) { if (YouPHPTubePlugin::isEnabled("996c9afb-b90e-40ca-90cb-934856180bb9")) {
require_once $global['systemRootPath'] . 'plugin/MP4ThumbsAndGif/MP4ThumbsAndGif.php'; require_once $global['systemRootPath'] . 'plugin/MP4ThumbsAndGif/MP4ThumbsAndGif.php';
$videoFileName = $video->getFilename(); $videoFileName = $video->getFilename();
MP4ThumbsAndGif::getImage($videoFileName, 'jpg'); MP4ThumbsAndGif::getImage($videoFileName, 'jpg');
MP4ThumbsAndGif::getImage($videoFileName, 'gif'); MP4ThumbsAndGif::getImage($videoFileName, 'gif');
} }
$obj->error = false; $obj->error = false;
$obj->filename = $filename; $obj->filename = $filename;
$obj->duration = $duration; $obj->duration = $duration;