From b3f5626c1e4e8041e0784434241d9fe53cb007a0 Mon Sep 17 00:00:00 2001 From: daniel Date: Sat, 13 Jul 2019 20:06:31 -0300 Subject: [PATCH] Bulk embed youtube videos test --- plugin/BulkEmbed/save.json.php | 23 ++++++++++------------- plugin/BulkEmbed/search.php | 32 ++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/plugin/BulkEmbed/save.json.php b/plugin/BulkEmbed/save.json.php index 2c8780875c71..dcea25ff307d 100644 --- a/plugin/BulkEmbed/save.json.php +++ b/plugin/BulkEmbed/save.json.php @@ -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'); diff --git a/plugin/BulkEmbed/search.php b/plugin/BulkEmbed/search.php index b932781af3ae..df016abf5e63 100644 --- a/plugin/BulkEmbed/search.php +++ b/plugin/BulkEmbed/search.php @@ -140,7 +140,6 @@ $("input:checkbox[name=videoCheckbox]").each(function () { videoLink.push($(this).val()); }); - console.log(videoLink); saveIt(videoLink); }); $('#getSelected').click(function () { @@ -148,16 +147,37 @@ $("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: 'plugin/BulkEmbed/save.json.php', - data: {"videoLink": videoLink}, + data: {"itemsToSave": itemsToSave}, type: 'post', success: function (response) { if (!response.error) { @@ -168,6 +188,7 @@ function saveIt(videoLink) { modal.hidePleaseWait(); } }); + } function search() { @@ -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); @@ -316,7 +336,7 @@ function getOutput(item) { '' + '' + '
' + - '

' + title + '

' + + '

' + title + '

' + 'By ' + channelTitle + ' on ' + videoDate + '' + '

' + description + '

' + '
' +