Skip to content

Commit

Permalink
Bulk embed youtube videos test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel authored and daniel committed Jul 13, 2019
1 parent 743476b commit b3f5626
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
23 changes: 10 additions & 13 deletions plugin/BulkEmbed/save.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@

if (!User::canUpload()) {
$obj->msg[] = __("Permission denied");
} else if (!empty($_POST['videoLink'])) {
} else if (!empty($_POST['itemsToSave'])) {

if (!is_array($_POST['videoLink'])) {
$_POST['videoLink'] = array($_POST['videoLink']);
}
foreach ($_POST['videoLink'] as $value) {
$info = url_get_contents($config->getEncoderURL() . "getLinkInfo/" . base64_encode($value));
$infoObj = json_decode($info);
foreach ($_POST['itemsToSave'] as $value) {
//$info = url_get_contents($config->getEncoderURL() . "getLinkInfo/" . base64_encode($value));
//$infoObj = json_decode($info);
$filename = uniqid("_YPTuniqid_", true);
$videos = new Video();
$videos->setFilename($filename);
$videos->setTitle($infoObj->title);
$videos->setClean_title($infoObj->title);
$videos->setDuration($infoObj->duration);
$videos->setDescription($infoObj->description);
file_put_contents($global['systemRootPath'] . "videos/{$filename}.jpg", base64_decode($infoObj->thumbs64));
$videos->setVideoLink($value);
$videos->setTitle($value['title']);
$videos->setClean_title($value['title']);
$videos->setDuration($value['duration']);
$videos->setDescription($value['description']);
file_put_contents($global['systemRootPath'] . "videos/{$filename}.jpg", $value['thumbs']);
$videos->setVideoLink($value['link']);
$videos->setType('embed');

$videos->setStatus('a');
Expand Down
32 changes: 26 additions & 6 deletions plugin/BulkEmbed/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,44 @@
$("input:checkbox[name=videoCheckbox]").each(function () {
videoLink.push($(this).val());
});
console.log(videoLink);
saveIt(videoLink);
});
$('#getSelected').click(function () {
var videoLink = new Array();
$("input:checkbox[name=videoCheckbox]:checked").each(function () {
videoLink.push($(this).val());
});
console.log(videoLink);
saveIt(videoLink);
});
});

function saveIt(videoLink) {
modal.showPleaseWait();

var itemsToSave = [];
for (x in videoLink) {
if (typeof videoLink[x] == 'function') {
continue;
}
$.ajax({
url: "https://www.googleapis.com/youtube/v3/videos?id="+videoLink[x]+"&part=id,snippet,contentDetails&key="+gapikey,

async: false,
success: function (data) {
var item = {};
item.link = "https://youtube.com/embed/" + data.items[0].id;
item.title = data.items[0].snippet.title;
item.description = data.items[0].snippet.description;
item.duration = data.items[0].contentDetails.duration;
item.thumbs = data.items[0].snippet.thumbnails.high.url;
itemsToSave.push(item);
}
});
}
console.log(itemsToSave);
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>plugin/BulkEmbed/save.json.php',
data: {"videoLink": videoLink},
data: {"itemsToSave": itemsToSave},
type: 'post',
success: function (response) {
if (!response.error) {
Expand All @@ -168,6 +188,7 @@ function saveIt(videoLink) {
modal.hidePleaseWait();
}
});

}

function search() {
Expand All @@ -191,10 +212,9 @@ function search() {
var prevPageToken = data.prevPageToken;

// Log data
console.log(data);
//console.log(data);

$.each(data.items, function (i, item) {

// Get Output
var output = getOutput(item);

Expand Down Expand Up @@ -316,7 +336,7 @@ function getOutput(item) {
'<img src="' + thumb + '">' +
'</div>' +
'<div class="list-right">' +
'<h3><input type="checkbox" value="https://youtube.com/embed/' + videoID + '" name="videoCheckbox"><a target="_blank" href="https://youtube.com/embed/' + videoID + '?rel=0">' + title + '</a></h3>' +
'<h3><input type="checkbox" value="' + videoID + '" name="videoCheckbox"><a target="_blank" href="https://youtube.com/embed/' + videoID + '?rel=0">' + title + '</a></h3>' +
'<small>By <span class="cTitle">' + channelTitle + '</span> on ' + videoDate + '</small>' +
'<p>' + description + '</p>' +
'</div>' +
Expand Down

0 comments on commit b3f5626

Please sign in to comment.