mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Version 7.5 Adding Articles support
This commit is contained in:
parent
e1d4f66780
commit
20205359cd
9 changed files with 127 additions and 42 deletions
|
@ -9,6 +9,7 @@ class BulkEmbed extends PluginAbstract {
|
|||
//$str = 'Set DEVELOPER_KEY to the "API key" value from the "Access" tab of the<br>Google Developers Console https://console.developers.google.com<br>Please ensure that you have enabled the YouTube Data API for your project.';
|
||||
//$str.= '<br>Add the Redirect URI '.$global['webSiteRootURL'].'plugin/BulkEmbed/youtubeSearch.json.php';
|
||||
$str = 'Create your API Key here https://console.developers.google.com/apis/credentials/key';
|
||||
$str .= "<br> Also make sure you enable the API YouTube Data API v3";
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
|
|
@ -193,6 +193,38 @@ $obj = YouPHPTubePlugin::getObjectData("BulkEmbed");
|
|||
}, 500);
|
||||
}
|
||||
|
||||
function validURL(str) {
|
||||
var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
|
||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
||||
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
||||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
||||
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
||||
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
||||
return !!pattern.test(str);
|
||||
}
|
||||
|
||||
function getFromUrl(url) {
|
||||
if (!validURL(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var regex = /[?&]([^=#]+)=([^&#]*)/g,
|
||||
params = {},
|
||||
match;
|
||||
while (match = regex.exec(url)) {
|
||||
params[match[1]] = match[2];
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
function getPlayListId(url) {
|
||||
var result = getFromUrl(url);
|
||||
if (result && typeof result.list !== 'undefined') {
|
||||
return result.list;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function search() {
|
||||
// clear
|
||||
$('#results').html('');
|
||||
|
@ -201,35 +233,57 @@ $obj = YouPHPTubePlugin::getObjectData("BulkEmbed");
|
|||
// get form input
|
||||
q = $('#query').val(); // this probably shouldn't be created as a global
|
||||
|
||||
// run get request on API
|
||||
$.get(
|
||||
"https://www.googleapis.com/youtube/v3/search", {
|
||||
part: 'snippet, id',
|
||||
q: q,
|
||||
type: 'video',
|
||||
key: gapikey,
|
||||
maxResults: 50,
|
||||
videoEmbeddable: "true"
|
||||
}, function (data) {
|
||||
var nextPageToken = data.nextPageToken;
|
||||
var prevPageToken = data.prevPageToken;
|
||||
var playListId = getPlayListId(q);
|
||||
|
||||
// Log data
|
||||
//console.log(data);
|
||||
|
||||
$.each(data.items, function (i, item) {
|
||||
// Get Output
|
||||
var output = getOutput(item);
|
||||
|
||||
// display results
|
||||
$('#results').append(output);
|
||||
if (playListId) {
|
||||
$.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 {
|
||||
// run get request on API
|
||||
$.get(
|
||||
"https://www.googleapis.com/youtube/v3/search", {
|
||||
part: 'snippet, id',
|
||||
q: q,
|
||||
type: 'video',
|
||||
key: gapikey,
|
||||
maxResults: 50,
|
||||
videoEmbeddable: "true"
|
||||
}, function (data) {
|
||||
processData(data);
|
||||
});
|
||||
}
|
||||
|
||||
var buttons = getButtons(prevPageToken, nextPageToken);
|
||||
}
|
||||
|
||||
// Display buttons
|
||||
$('#buttons').append(buttons);
|
||||
function processData(data) {
|
||||
var nextPageToken = data.nextPageToken;
|
||||
var prevPageToken = data.prevPageToken;
|
||||
|
||||
// Log data
|
||||
//console.log(data);
|
||||
|
||||
$.each(data.items, function (i, item) {
|
||||
// Get Output
|
||||
var output = getOutput(item);
|
||||
|
||||
// display results
|
||||
$('#results').append(output);
|
||||
});
|
||||
|
||||
var buttons = getButtons(prevPageToken, nextPageToken);
|
||||
|
||||
// Display buttons
|
||||
$('#buttons').append(buttons);
|
||||
}
|
||||
|
||||
// Next page function
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue