mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Auto create a playlist when bulk embed
This commit is contained in:
parent
20205359cd
commit
3b708cabe3
3 changed files with 74 additions and 22 deletions
|
@ -18,6 +18,33 @@ class PlayList extends ObjectYPT {
|
||||||
static function getTableName() {
|
static function getTableName() {
|
||||||
return 'playlists';
|
return 'playlists';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static protected function getFromDbFromName($name) {
|
||||||
|
global $global;
|
||||||
|
$sql = "SELECT * FROM " . static::getTableName() . " WHERE name = ? users_id = ". User::getId()." LIMIT 1";
|
||||||
|
$res = sqlDAL::readSql($sql, "s", array($name));
|
||||||
|
$data = sqlDAL::fetchAssoc($res);
|
||||||
|
sqlDAL::close($res);
|
||||||
|
if ($res) {
|
||||||
|
$row = $data;
|
||||||
|
} else {
|
||||||
|
$row = false;
|
||||||
|
}
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadFromName($name) {
|
||||||
|
if(!User::isLogged()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$row = self::getFromDbFromName($name);
|
||||||
|
if (empty($row))
|
||||||
|
return false;
|
||||||
|
foreach ($row as $key => $value) {
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,39 +1,40 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert ISO 8601 values like PT15M33S
|
* Convert ISO 8601 values like PT15M33S
|
||||||
* to a total value of seconds.
|
* to a total value of seconds.
|
||||||
*
|
*
|
||||||
* @param string $ISO8601
|
* @param string $ISO8601
|
||||||
*/
|
*/
|
||||||
function ISO8601ToSeconds($ISO8601)
|
function ISO8601ToSeconds($ISO8601) {
|
||||||
{
|
|
||||||
preg_match('/\d{1,2}[H]/', $ISO8601, $hours);
|
preg_match('/\d{1,2}[H]/', $ISO8601, $hours);
|
||||||
preg_match('/\d{1,2}[M]/', $ISO8601, $minutes);
|
preg_match('/\d{1,2}[M]/', $ISO8601, $minutes);
|
||||||
preg_match('/\d{1,2}[S]/', $ISO8601, $seconds);
|
preg_match('/\d{1,2}[S]/', $ISO8601, $seconds);
|
||||||
|
|
||||||
$duration = [
|
$duration = [
|
||||||
'hours' => $hours ? $hours[0] : 0,
|
'hours' => $hours ? $hours[0] : 0,
|
||||||
'minutes' => $minutes ? $minutes[0] : 0,
|
'minutes' => $minutes ? $minutes[0] : 0,
|
||||||
'seconds' => $seconds ? $seconds[0] : 0,
|
'seconds' => $seconds ? $seconds[0] : 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
$hours = substr($duration['hours'], 0, -1);
|
$hours = substr($duration['hours'], 0, -1);
|
||||||
$minutes = substr($duration['minutes'], 0, -1);
|
$minutes = substr($duration['minutes'], 0, -1);
|
||||||
$seconds = substr($duration['seconds'], 0, -1);
|
$seconds = substr($duration['seconds'], 0, -1);
|
||||||
|
|
||||||
$hours = intval(@$hours);
|
$hours = intval(@$hours);
|
||||||
$minutes = intval(@$minutes);
|
$minutes = intval(@$minutes);
|
||||||
$seconds = intval(@$seconds);
|
$seconds = intval(@$seconds);
|
||||||
|
|
||||||
$toltalSeconds = ($hours * 60 * 60) + ($minutes * 60) + $seconds;
|
$toltalSeconds = ($hours * 60 * 60) + ($minutes * 60) + $seconds;
|
||||||
|
|
||||||
return $toltalSeconds;
|
return $toltalSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ISO8601ToDuration($ISO8601){
|
function ISO8601ToDuration($ISO8601) {
|
||||||
$seconds = ISO8601ToSeconds($ISO8601);
|
$seconds = ISO8601ToSeconds($ISO8601);
|
||||||
return secondsToVideoTime($seconds);
|
return secondsToVideoTime($seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
//error_reporting(0);
|
//error_reporting(0);
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
if (!isset($global['systemRootPath'])) {
|
if (!isset($global['systemRootPath'])) {
|
||||||
|
@ -43,16 +44,26 @@ if (!isset($global['systemRootPath'])) {
|
||||||
$obj = new stdClass();
|
$obj = new stdClass();
|
||||||
$obj->error = true;
|
$obj->error = true;
|
||||||
$obj->msg = array();
|
$obj->msg = array();
|
||||||
|
$obj->playListId = 0;
|
||||||
|
|
||||||
|
|
||||||
$objo = YouPHPTubePlugin::getObjectDataIfEnabled('BulkEmbed');
|
$objo = YouPHPTubePlugin::getObjectDataIfEnabled('BulkEmbed');
|
||||||
if(empty($objo) || ($objo->onlyAdminCanBulkEmbed && !User::isAdmin())){
|
if (empty($objo) || ($objo->onlyAdminCanBulkEmbed && !User::isAdmin())) {
|
||||||
$obj->msg[] = __("Permission denied");
|
$obj->msg[] = __("Permission denied");
|
||||||
$obj->msg[] = "Plugin disabled";
|
$obj->msg[] = "Plugin disabled";
|
||||||
}else if (!User::canUpload()) {
|
} else if (!User::canUpload()) {
|
||||||
$obj->msg[] = __("Permission denied");
|
$obj->msg[] = __("Permission denied");
|
||||||
$obj->msg[] = "User can not upload videos";
|
$obj->msg[] = "User can not upload videos";
|
||||||
} else if (!empty($_POST['itemsToSave'])) {
|
} else if (!empty($_POST['itemsToSave'])) {
|
||||||
|
|
||||||
|
if (!empty($_POST['playListName'])) {
|
||||||
|
require_once $global['systemRootPath'] . 'objects/playlist.php';
|
||||||
|
$playList = new PlayList(0);
|
||||||
|
$playList->loadFromName($_POST['playListName']);
|
||||||
|
$playList->setName($_POST['playListName']);
|
||||||
|
$playList->setStatus('p');
|
||||||
|
$obj->playListId = $playList->save();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($_POST['itemsToSave'] as $value) {
|
foreach ($_POST['itemsToSave'] as $value) {
|
||||||
foreach ($value as $key => $value2) {
|
foreach ($value as $key => $value2) {
|
||||||
|
@ -81,12 +92,16 @@ if(empty($objo) || ($objo->onlyAdminCanBulkEmbed && !User::isAdmin())){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!empty($resp) && !empty($obj->playListId)){
|
||||||
|
$playList = new PlayList($obj->playListId);
|
||||||
|
$playList->addVideo($resp, true);
|
||||||
|
}
|
||||||
|
|
||||||
YouPHPTubePlugin::afterNewVideo($resp);
|
YouPHPTubePlugin::afterNewVideo($resp);
|
||||||
|
|
||||||
YouPHPTubePlugin::saveVideosAddNew($_POST, $resp);
|
YouPHPTubePlugin::saveVideosAddNew($_POST, $resp);
|
||||||
|
|
||||||
$obj->msg[] = Video::getVideoLight($resp);
|
$obj->msg[] = Video::getVideoLight($resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ $obj = YouPHPTubePlugin::getObjectData("BulkEmbed");
|
||||||
<form id="search-form" name="search-form" onsubmit="return search()">
|
<form id="search-form" name="search-form" onsubmit="return search()">
|
||||||
<div id="custom-search-input">
|
<div id="custom-search-input">
|
||||||
<div class="input-group col-md-12">
|
<div class="input-group col-md-12">
|
||||||
<input type="search" id="query" class="form-control input-lg" placeholder="Search YouTube" />
|
<input type="search" id="query" class="form-control input-lg" placeholder="Search YouTube / PlayList URL" />
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button class="btn btn-info btn-lg" type="button">
|
<button class="btn btn-info btn-lg" type="button">
|
||||||
<i class="glyphicon glyphicon-search"></i>
|
<i class="glyphicon glyphicon-search"></i>
|
||||||
|
@ -133,6 +133,7 @@ $obj = YouPHPTubePlugin::getObjectData("BulkEmbed");
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var gapikey = '<?php echo $obj->API_KEY; ?>';
|
var gapikey = '<?php echo $obj->API_KEY; ?>';
|
||||||
|
var playListName = '';
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$('#search-form').submit(function (e) {
|
$('#search-form').submit(function (e) {
|
||||||
|
@ -179,7 +180,7 @@ $obj = YouPHPTubePlugin::getObjectData("BulkEmbed");
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '<?php echo $global['webSiteRootURL']; ?>plugin/BulkEmbed/save.json.php',
|
url: '<?php echo $global['webSiteRootURL']; ?>plugin/BulkEmbed/save.json.php',
|
||||||
data: {"itemsToSave": itemsToSave},
|
data: {"itemsToSave": itemsToSave, playListName: playListName},
|
||||||
type: 'post',
|
type: 'post',
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (!response.error) {
|
if (!response.error) {
|
||||||
|
@ -237,18 +238,27 @@ $obj = YouPHPTubePlugin::getObjectData("BulkEmbed");
|
||||||
|
|
||||||
if (playListId) {
|
if (playListId) {
|
||||||
$.get(
|
$.get(
|
||||||
"https://www.googleapis.com/youtube/v3/playlistItems", {
|
"https://www.googleapis.com/youtube/v3/playlists", {
|
||||||
part: 'snippet, id',
|
part: 'snippet',
|
||||||
q: q,
|
|
||||||
type: 'video',
|
|
||||||
key: gapikey,
|
key: gapikey,
|
||||||
maxResults: 50,
|
id: playListId
|
||||||
videoEmbeddable: "true",
|
|
||||||
playlistId: playListId
|
|
||||||
}, function (data) {
|
}, function (data) {
|
||||||
processData(data);
|
playListName = data.snippet.title;
|
||||||
|
$.get(
|
||||||
|
"https://www.googleapis.com/youtube/v3/playlistItems", {
|
||||||
|
part: 'snippet, id',
|
||||||
|
q: q,
|
||||||
|
type: 'video',
|
||||||
|
key: gapikey,
|
||||||
|
maxResults: 50,
|
||||||
|
videoEmbeddable: "true",
|
||||||
|
playlistId: playListId
|
||||||
|
}, function (data) {
|
||||||
|
processData(data);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
playListName = '';
|
||||||
// run get request on API
|
// run get request on API
|
||||||
$.get(
|
$.get(
|
||||||
"https://www.googleapis.com/youtube/v3/search", {
|
"https://www.googleapis.com/youtube/v3/search", {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue