Это просто. После того, как вы интегрируете свой код с Youtube API, он вернет объект, похожий на результат, который вы можете установить практически с API (количество результатов, дата и т. Д.). Итак, основываясь на этом, вы можете сформировать его так, как хотите.
Ниже приведен пример JQuery с некоторым лечением в результате:
function tplawesome(e,t){res=e;for(var n=0;n<t.length;n++){res=res.replace(/\{\{(.*?)\}\}/g,function(e,r){return t[n][r]})}return res}
$(function() {
$("#search-btn").on("click", function(e){
e.preventDefault();
//prepare the request
var request = gapi.client.youtube.search.list({
part: "snippet",
type: "video",
q: encodeURIComponent($("#input-search").val()).replace(/%20/g, "+"),
maxResults: 6,
order: "viewCount",
publishedAfter: "2015-01-01T00:00:00Z"
});
request.execute(function(response){
var results = response.result;
function getMonth(monthNumber){
var monthName = ['jan', 'fevereiro', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'];
return monthName[monthNumber-1];
}
var dateUTC = results.items[0].snippet.publishedAt;
var year = dateUTC.substring(0,4);
var day = dateUTC.substring(8,10);
var month = dateUTC.substring(5,7);
month = getMonth(month);
var finalDate = day + " de " + month + " de " + year;
console.log("passou", results.items[0].snippet.description);
//$.each(results.items, function(index, item){
$.get("youtube/item", function(data){
$("#results").append(tplawesome(data, [{ "videoId":results.items[0].id.videoId}]));
});
$.get("youtube/title", function(data){
$(".info-title").append(tplawesome(data,[{"title": results.items[0].snippet.title, "videoId":results.items[0].id.videoId}]));
});
$.get("youtube/description", function(data){
$(".info-description").append(tplawesome(data,[{"description": results.items[0].snippet.description, "videoId":results.items[0].id.videoId}]));
});
$.get("youtube/finalDate", function(data){
$(".publishedTime").append(tplawesome(data, [{finalDate}]));
});
$.get("youtube/relationVideo", function(data){
$(".relationVideo-container").append(tplawesome(data,[{"title": results.items[1].snippet.title, "videoId":results.items[1].id.videoId}]));
});
$.get("youtube/relationVideo", function(data){
$(".relationVideo-container").append(tplawesome(data,[{"title": results.items[2].snippet.title, "videoId":results.items[2].id.videoId}]));
});
});
});
});
function init(){ gapi.client.setApiKey("AIzaSyDuLpwiCe78V9p0JE5rQaygB2XVgIDHjhs");
gapi.client.load("youtube", "v3", function(){
//youtube API ok
});
}
$(document).ready(function(){
$("#search-btn").on("click", function(){
$('#info-section').addClass('show');
$('#video-section').addClass('show');
$('#description-section').addClass('show');
});
Вы можете увидеть простой проект с Youtube API, NodeJS и экспрессом here.
используйте сервер .. Если вы не знаете, как создать свой собственный, пожалуйста, используйте [diff bot] (https://www.diffbot.com/dev/docs/article/) – ymz