mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Start S3 Integration
https://github.com/DanielnetoDotCom/YouPHPTube/issues/293 https://github.com/DanielnetoDotCom/YouPHPTube/issues/295 https://github.com/DanielnetoDotCom/YouPHPTube/issues/353
This commit is contained in:
parent
3b3c32b535
commit
58b86c39cf
5 changed files with 107 additions and 79 deletions
|
@ -616,7 +616,15 @@ function getimgsize($file_src){
|
|||
$name = "getimgsize_". md5($file_src);
|
||||
$cached = ObjectYPT::getCache($name, 86400);//one day
|
||||
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);
|
||||
|
@ -702,3 +710,29 @@ function im_resize($file_src, $file_dest, $wd, $hd) {
|
|||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -668,23 +668,39 @@ class Video {
|
|||
if (empty($resp)) {
|
||||
die('Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
|
||||
} else {
|
||||
$path = self::getStoragePath();
|
||||
foreach (self::$types as $value) {
|
||||
$file = "{$path}original_{$video['filename']}";
|
||||
if (file_exists($file)) {
|
||||
@unlink($file);
|
||||
$this->removeFiles($video['filename']);
|
||||
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
|
||||
if(!empty($aws_s3)){
|
||||
$aws_s3->removeFiles($video['filename']);
|
||||
}
|
||||
}
|
||||
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("{$path}{$video['filename']}.*");
|
||||
$files = glob("{$filePath}.*");
|
||||
foreach ($files as $file) {
|
||||
if (file_exists($file)) {
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
function setDescription($description) {
|
||||
$this->description = $description;
|
||||
|
@ -752,12 +768,12 @@ class Video {
|
|||
$getID3 = new getID3;
|
||||
// Analyze file and store returned data in $ThisFileInfo
|
||||
$ThisFileInfo = $getID3->analyze($file);
|
||||
return static::getCleanDuration($ThisFileInfo['playtime_string']);
|
||||
return static::getCleanDuration(@$ThisFileInfo['playtime_string']);
|
||||
}
|
||||
|
||||
function updateDurationIfNeed($fileExtension = ".mp4") {
|
||||
global $global;
|
||||
$source = self::getSourceFile($this->filename, $fileExtension);
|
||||
$source = self::getSourceFile($this->filename, $fileExtension, true);
|
||||
$file = $source['path'];
|
||||
|
||||
if (!empty($this->id) && $this->duration == "EE:EE:EE" && file_exists($file)) {
|
||||
|
@ -1193,7 +1209,7 @@ class Video {
|
|||
* @param type $type
|
||||
* @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;
|
||||
$name = "getSourceFile_{$filename}{$type}_";
|
||||
$cached = ObjectYPT::getCache($name, 86400);//one day
|
||||
|
@ -1203,12 +1219,15 @@ class Video {
|
|||
$source = array();
|
||||
$source['path'] = "{$global['systemRootPath']}videos/{$filename}{$type}";
|
||||
$source['url'] = "{$global['webSiteRootURL']}videos/{$filename}{$type}";
|
||||
/* need it because getDurationFromFile*/
|
||||
if($includeS3){
|
||||
if (!file_exists($source['path']) || filesize($source['path']) < 1024) {
|
||||
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
|
||||
if (!empty($aws_s3)) {
|
||||
$source = $aws_s3->getAddress("{$filename}{$type}");
|
||||
}
|
||||
}
|
||||
}
|
||||
ObjectYPT::setCache($name, $source);
|
||||
return $source;
|
||||
}
|
||||
|
@ -1234,18 +1253,18 @@ class Video {
|
|||
$gifSource = self::getSourceFile($filename, ".gif");
|
||||
$jpegSource = self::getSourceFile($filename, ".jpg");
|
||||
$thumbsSource = self::getSourceFile($filename, "_thumbs.jpg");
|
||||
$obj->poster = "";
|
||||
$obj->thumbsGif = "";
|
||||
$obj->thumbsJpg = "";
|
||||
$obj->poster = $jpegSource['url'];
|
||||
$obj->thumbsGif = $gifSource['url'];
|
||||
$obj->thumbsJpg = $thumbsSource['url'];
|
||||
if ($type !== "audio") {
|
||||
if (file_exists($gifSource['path'])) {
|
||||
$obj->thumbsGif = $gifSource['url'];
|
||||
}
|
||||
if (file_exists($jpegSource['path']) && filesize($jpegSource['path']) > 1024) {
|
||||
if (file_exists($jpegSource['path'])) {
|
||||
$obj->poster = $jpegSource['url'];
|
||||
$obj->thumbsJpg = $thumbsSource['url'];
|
||||
// create thumbs
|
||||
if (!file_exists($thumbsSource['path'])) {
|
||||
if (!file_exists($thumbsSource['path']) && filesize($jpegSource['path']) > 1024) {
|
||||
im_resize($jpegSource['path'], $thumbsSource['path'], 250, 140);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -66,53 +66,30 @@ if (empty($videoFileName)) {
|
|||
|
||||
$destination_local = "{$global['systemRootPath']}videos/{$videoFileName}";
|
||||
// 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'])) {
|
||||
$resolution = "";
|
||||
if (!empty($_POST['resolution'])) {
|
||||
$resolution = "_{$_POST['resolution']}";
|
||||
}
|
||||
$destination_resolution_file = "{$destination}{$resolution}.{$_POST['format']}";
|
||||
if (!move_uploaded_file($_FILES['video']['tmp_name'], $destination_resolution_file)) {
|
||||
$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 " );
|
||||
}
|
||||
$filename = "{$videoFileName}{$resolution}.{$_POST['format']}";
|
||||
decideMoveUploadedToVideos($_FILES['video']['tmp_name'], $filename);
|
||||
} else {
|
||||
// set encoding
|
||||
$video->setStatus('e');
|
||||
}
|
||||
if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination}.jpg")) {
|
||||
if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$destination}.jpg")) {
|
||||
$obj->msg = print_r(sprintf(__("Could not move image file [%s.jpg]"), $destination), true);
|
||||
if (!empty($_FILES['image']['tmp_name']) && !file_exists("{$destination_local}.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_local), true);
|
||||
error_log($obj->msg);
|
||||
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}.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);
|
||||
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);
|
||||
error_log($obj->msg);
|
||||
die(json_encode($obj));
|
||||
}
|
||||
if(!empty($aws_s3)){
|
||||
file_put_contents( "{$destination_local}.gif" , "Dummy File" );
|
||||
}
|
||||
}
|
||||
$video_id = $video->save();
|
||||
$video->updateDurationIfNeed();
|
||||
|
|
|
@ -162,6 +162,11 @@ class YouPHPTubePlugin{
|
|||
return !empty(Plugin::getEnabled($uuid));
|
||||
}
|
||||
|
||||
static function isEnabledByName($name){
|
||||
$p = static::loadPluginIfEnabled($name);
|
||||
return !empty($p);
|
||||
}
|
||||
|
||||
static function getLogin(){
|
||||
$plugins = Plugin::getAllEnabled();
|
||||
$logins = array();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
$configFile = '../../videos/configuration.php';
|
||||
if (!file_exists($configFile)) {
|
||||
$configFile = '../videos/configuration.php';
|
||||
|
@ -35,18 +36,10 @@ if (isset($_FILES['upl']) && $_FILES['upl']['error'] == 0) {
|
|||
/**
|
||||
* 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');
|
||||
if(!empty($aws_s3)){
|
||||
file_put_contents( "{$global['systemRootPath']}videos/{$filename}.mp4" , "Dummy File" );
|
||||
}
|
||||
$tmp_name = $_FILES['upl']['tmp_name'];
|
||||
$filenameMP4 = $filename . ".mp4";
|
||||
decideMoveUploadedToVideos($tmp_name, $filenameMP4);
|
||||
|
||||
|
||||
if (YouPHPTubePlugin::isEnabled("996c9afb-b90e-40ca-90cb-934856180bb9")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue