mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 02:39:46 +02:00
Add an option for bulk import videos
This commit is contained in:
parent
822d6361a4
commit
7f7ee26b9b
8 changed files with 285 additions and 4 deletions
|
@ -726,13 +726,19 @@ function im_resize($file_src, $file_dest, $wd, $hd, $q = 50) {
|
||||||
|
|
||||||
function decideMoveUploadedToVideos($tmp_name, $filename) {
|
function decideMoveUploadedToVideos($tmp_name, $filename) {
|
||||||
global $global;
|
global $global;
|
||||||
|
$obj = new stdClass();
|
||||||
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
|
$aws_s3 = YouPHPTubePlugin::loadPluginIfEnabled('AWS_S3');
|
||||||
if (!empty($aws_s3)) {
|
if (!empty($aws_s3)) {
|
||||||
$aws_s3->move_uploaded_file($tmp_name, $filename);
|
$aws_s3->move_uploaded_file($tmp_name, $filename);
|
||||||
} else {
|
} else {
|
||||||
if (!move_uploaded_file($tmp_name, "{$global['systemRootPath']}videos/{$filename}")) {
|
if (!move_uploaded_file($tmp_name, "{$global['systemRootPath']}videos/{$filename}")) {
|
||||||
$obj->msg = "Error on move_uploaded_file({$tmp_name}, {$global['systemRootPath']}videos/{$filename})";
|
if(!rename($tmp_name, "{$global['systemRootPath']}videos/{$filename}")){
|
||||||
die(json_encode($obj));
|
if(!copy($tmp_name, "{$global['systemRootPath']}videos/{$filename}")){
|
||||||
|
$obj->msg = "Error on decideMoveUploadedToVideos({$tmp_name}, {$global['systemRootPath']}videos/{$filename})";
|
||||||
|
die(json_encode($obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
65
objects/import.json.php
Normal file
65
objects/import.json.php
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../videos/configuration.php';
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
if (!User::canUpload() || !empty($advancedCustom->doNotShowImportMP4Button)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$obj = new stdClass();
|
||||||
|
|
||||||
|
$obj->error = true;
|
||||||
|
|
||||||
|
$obj->fileURI = pathinfo($_POST['fileURI']);
|
||||||
|
|
||||||
|
//get description
|
||||||
|
$filename = $obj->fileURI['dirname'].DIRECTORY_SEPARATOR.$obj->fileURI['filename'];
|
||||||
|
$extensions = array('txt', 'html', 'htm');
|
||||||
|
|
||||||
|
foreach ($extensions as $value) {
|
||||||
|
$_POST['description'] = "";
|
||||||
|
$_POST['title'] = "";
|
||||||
|
if(file_exists("{$filename}.{$value}")){
|
||||||
|
$html = file_get_contents("{$filename}.{$value}");
|
||||||
|
$breaks = array("<br />","<br>","<br/>");
|
||||||
|
$html = str_ireplace($breaks, "\r\n", $html);
|
||||||
|
$_POST['description'] = $html;
|
||||||
|
$cleanHTML = strip_tags($html);
|
||||||
|
$_POST['title'] = substr($cleanHTML, 0, $_POST['length']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmpDir = sys_get_temp_dir();
|
||||||
|
$tmpFileName = $tmpDir.DIRECTORY_SEPARATOR.$obj->fileURI['filename'];
|
||||||
|
$source = $obj->fileURI['dirname'].DIRECTORY_SEPARATOR.$obj->fileURI['basename'];
|
||||||
|
|
||||||
|
if (!copy($source, $tmpFileName)) {
|
||||||
|
$obj->msg = "failed to copy $filename...\n";
|
||||||
|
die(json_encode($obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($_POST['delete']) && $_POST['delete']!=='false'){
|
||||||
|
if(is_writable($source)){
|
||||||
|
unlink($source);
|
||||||
|
foreach ($extensions as $value) {
|
||||||
|
if(file_exists("{$filename}.{$value}")){
|
||||||
|
unlink("{$filename}.{$value}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$obj->msg = "Could not delete $source...\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$_FILES['upl']['error'] = 0;
|
||||||
|
$_FILES['upl']['name'] = $obj->fileURI['basename'];
|
||||||
|
$_FILES['upl']['tmp_name'] = $tmpFileName;
|
||||||
|
$_FILES['upl']['type'] = "video/mp4";
|
||||||
|
$_FILES['upl']['size'] = filesize($tmpFileName);
|
||||||
|
|
||||||
|
require_once $global['systemRootPath'] . 'view/mini-upload-form/upload.php';
|
||||||
|
|
||||||
|
|
||||||
|
echo json_encode($obj);
|
34
objects/listFiles.json.php
Normal file
34
objects/listFiles.json.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../videos/configuration.php';
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
if (!User::canUpload() || !empty($advancedCustom->doNotShowImportMP4Button)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$global['allowed'] = array('mp4');
|
||||||
|
$files = array();
|
||||||
|
if (!empty($_POST['path'])) {
|
||||||
|
$path = $_POST['path'];
|
||||||
|
if (substr($path, -1) !== '/') {
|
||||||
|
$path .= "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists($path)) {
|
||||||
|
$filesStr = "{*." . implode(",*.", $global['allowed']) . "}";
|
||||||
|
|
||||||
|
//echo $files;
|
||||||
|
$video_array = glob($path . $filesStr, GLOB_BRACE);
|
||||||
|
|
||||||
|
$id = 0;
|
||||||
|
foreach ($video_array as $key => $value) {
|
||||||
|
$path_parts = pathinfo($value);
|
||||||
|
$obj = new stdClass();
|
||||||
|
$obj->id = $id++;
|
||||||
|
$obj->path = utf8_encode($value);
|
||||||
|
$obj->name = utf8_encode($path_parts['basename']);
|
||||||
|
$files[] = $obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($files);
|
|
@ -17,6 +17,8 @@ foreach ($videos as $key => $value) {
|
||||||
//$categories[$key]['comment'] = " <div class=\"commenterName\"><strong>{$name}</strong><div class=\"date sub-text\">{$value['created']}</div></div><div class=\"commentText\">". nl2br($value['comment'])."</div>";
|
//$categories[$key]['comment'] = " <div class=\"commenterName\"><strong>{$name}</strong><div class=\"date sub-text\">{$value['created']}</div></div><div class=\"commentText\">". nl2br($value['comment'])."</div>";
|
||||||
$videos[$key]['creator'] = '<div class="pull-left"><img src="'.User::getPhoto($value['users_id']).'" alt="" class="img img-responsive img-circle" style="max-width: 50px;"/></div><div class="commentDetails"><div class="commenterName"><strong>'.$name.'</strong> <small>'.humanTiming(strtotime($value['videoCreation'])).'</small></div></div>';
|
$videos[$key]['creator'] = '<div class="pull-left"><img src="'.User::getPhoto($value['users_id']).'" alt="" class="img img-responsive img-circle" style="max-width: 50px;"/></div><div class="commentDetails"><div class="commenterName"><strong>'.$name.'</strong> <small>'.humanTiming(strtotime($value['videoCreation'])).'</small></div></div>';
|
||||||
$videos[$key]['next_video'] = array();
|
$videos[$key]['next_video'] = array();
|
||||||
|
$videos[$key]['description'] = utf8_encode($videos[$key]['description']);
|
||||||
|
$videos[$key]['title'] = utf8_encode($videos[$key]['title']);
|
||||||
if(!empty($videos[$key]['next_videos_id'])){
|
if(!empty($videos[$key]['next_videos_id'])){
|
||||||
unset($_POST['searchPhrase']);
|
unset($_POST['searchPhrase']);
|
||||||
$videos[$key]['next_video'] = Video::getVideo($videos[$key]['next_videos_id']);
|
$videos[$key]['next_video'] = Video::getVideo($videos[$key]['next_videos_id']);
|
||||||
|
|
|
@ -20,6 +20,7 @@ class CustomizeAdvanced extends PluginAbstract {
|
||||||
public function getEmptyDataObject() {
|
public function getEmptyDataObject() {
|
||||||
$obj = new stdClass();
|
$obj = new stdClass();
|
||||||
$obj->doNotShowUploadMP4Button = true;
|
$obj->doNotShowUploadMP4Button = true;
|
||||||
|
$obj->doNotShowImportMP4Button = false;
|
||||||
$obj->doNotShowEncoderButton = false;
|
$obj->doNotShowEncoderButton = false;
|
||||||
$obj->doNotShowEmbedButton = false;
|
$obj->doNotShowEmbedButton = false;
|
||||||
$obj->doNotShowEncoderResolutionLow = false;
|
$obj->doNotShowEncoderResolutionLow = false;
|
||||||
|
|
156
view/import.php
Normal file
156
view/import.php
Normal file
|
@ -0,0 +1,156 @@
|
||||||
|
<?php
|
||||||
|
require_once '../videos/configuration.php';
|
||||||
|
if (!User::canUpload() || !empty($advancedCustom->doNotShowImportMP4Button)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="<?php echo $config->getLanguage(); ?>">
|
||||||
|
<head>
|
||||||
|
<title><?php echo $config->getWebSiteTitle(); ?> :: <?php echo __("About"); ?></title>
|
||||||
|
<?php
|
||||||
|
include $global['systemRootPath'] . 'view/include/head.php';
|
||||||
|
?>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
include $global['systemRootPath'] . 'view/include/navbar.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">Import Local Videos</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<i class="fas fa-question-circle"></i>
|
||||||
|
Here you can direct import multiple videos stored on your hard drive.<br>
|
||||||
|
If there is a file (html or htm or txt) we will import it's content as a description, and the first
|
||||||
|
<input type="number" id="length" value="50" style="width: 70px;" /> characteres will be the file title. (choose 0 to use the file name as the title)
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="checkbox">
|
||||||
|
<label><input type="checkbox" value="delete" id="delete"> <?php echo __("Delete files after submit"); ?></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" id="path" class="form-control" placeholder="Local Path of videos i.e. /media/videos"/>
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-secondary" id="pathBtn">
|
||||||
|
<span class="glyphicon glyphicon-list"></span> <?php echo __("List Files"); ?>
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-secondary" id="checkBtn">
|
||||||
|
<i class="far fa-check-square" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-secondary" id="uncheckBtn">
|
||||||
|
<i class="far fa-square" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<select class="form-control" id="bulk_categories_id" name="bulk_categories_id">
|
||||||
|
|
||||||
|
<option value="0">Category - Use site default</option>
|
||||||
|
<?php
|
||||||
|
foreach ($_SESSION['login']->categories as $key => $value) {
|
||||||
|
echo '<option value="' . $value->id . '">' . $value->name . '</option>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<ul class="list-group" id="files">
|
||||||
|
</ul>
|
||||||
|
<button class="btn btn-block btn-primary" id="addQueueBtn">Add on Queue</button>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div><!--/.container-->
|
||||||
|
<?php
|
||||||
|
include $global['systemRootPath'] . 'view/include/footer.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function checkFiles() {
|
||||||
|
var path = $('#path').val();
|
||||||
|
if (!path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: webSiteRootURL + 'objects/listFiles.json.php',
|
||||||
|
data: {"path": path},
|
||||||
|
type: 'post',
|
||||||
|
success: function (response) {
|
||||||
|
$('#files').empty();
|
||||||
|
if (response) {
|
||||||
|
for (i = 0; i < response.length; i++) {
|
||||||
|
if (!response[i])
|
||||||
|
continue;
|
||||||
|
$('#files').append('<li class="list-group-item" path="' + response[i].path + '" id="li' + i + '"><span class="label label-success" style="display: none;"><span class="glyphicon glyphicon-ok"></span> Added on queue.. </span> ' + response[i].name + '<div class="material-switch pull-right"><input id="someSwitchOption' + response[i].id + '" class="someSwitchOption" type="checkbox"/><label for="someSwitchOption' + response[i].id + '" class="label-primary"></label></div></li>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var importing = 0;
|
||||||
|
$(document).ready(function () {
|
||||||
|
|
||||||
|
|
||||||
|
$("#checkBtn").click(function () {
|
||||||
|
$('#files').find('input:checkbox').prop('checked', true);
|
||||||
|
});
|
||||||
|
$("#uncheckBtn").click(function () {
|
||||||
|
$('#files').find('input:checkbox').prop('checked', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#pathBtn").click(function () {
|
||||||
|
checkFiles();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#addQueueBtn").click(function () {
|
||||||
|
importing = 0;
|
||||||
|
modal.showPleaseWait();
|
||||||
|
$('#files li').each(function () {
|
||||||
|
if ($(this).find('.someSwitchOption').is(":checked")) {
|
||||||
|
importing++;
|
||||||
|
console.log("+ "+importing);
|
||||||
|
var id = $(this).attr('id');
|
||||||
|
$.ajax({
|
||||||
|
url: webSiteRootURL + 'objects/import.json.php',
|
||||||
|
data: {
|
||||||
|
"fileURI": $(this).attr('path'),
|
||||||
|
"categories_id": $('#bulk_categories_id').val(),
|
||||||
|
"length": $('#length').val(),
|
||||||
|
"delete": $('#delete').is(":checked")
|
||||||
|
},
|
||||||
|
type: 'post',
|
||||||
|
success: function (response) {
|
||||||
|
importing--;
|
||||||
|
console.log("- "+importing);
|
||||||
|
$('#' + id).find('.label').fadeIn();
|
||||||
|
if (!importing) {
|
||||||
|
modal.hidePleaseWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -110,6 +110,15 @@ $updateFiles = getUpdatesFilesArray();
|
||||||
</li>
|
</li>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
if (empty($advancedCustom->doNotShowImportMP4Button)) {
|
||||||
|
?>
|
||||||
|
<li>
|
||||||
|
<a href="<?php echo $global['webSiteRootURL']; ?>view/import.php" >
|
||||||
|
<span class="fas fa-hdd"></span> <?php echo __("Direct Import Local Videos"); ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
if (empty($advancedCustom->doNotShowEmbedButton)) {
|
if (empty($advancedCustom->doNotShowEmbedButton)) {
|
||||||
?>
|
?>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -44,13 +44,21 @@ if (isset($_FILES['upl']) && $_FILES['upl']['error'] == 0)
|
||||||
$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);
|
||||||
|
|
||||||
|
if(!empty($_POST['title'])){
|
||||||
|
$video->setTitle($_POST['title']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($_POST['description'])){
|
||||||
|
$video->setDescription($_POST['description']);
|
||||||
|
}
|
||||||
|
|
||||||
if ($extension == "mp4")
|
if ($extension == "mp4")
|
||||||
{
|
{
|
||||||
$video->setType("video");
|
$video->setType("video");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (($extension == "mp3") || ($extension == "ogg"))
|
if (($extension == "mp3") || ($extension == "ogg")){
|
||||||
{
|
|
||||||
$video->setType("audio");
|
$video->setType("audio");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue