First of all, thank you for answering, I took a look at the Youtube API but I couldn’t find what I was looking for just a few examples that I had trouble understanding. So I entered the source code of the website from which I recorded the video and I will post the codes that I found here to see if you or someone else can help me understand it and get it to work:
In a file . js found:
// Adiciona vÃdeo ao STREAM
root.delegate('#includeVideoStream','click',function(){
var streamLink = getURL($("#stream-video").val());
if(streamLink && !$('#stream-link-status').attr('value')){
var video = $('#stream-video').val();
$('#add-stream-image').parent().hide();
$('#stream-description').append(video);
$('#stream-video').val('');
$('.formPublishVideo').hide();
$('#cont-video-publish').hide();
if(streamLink[0]=='YOUTUBE'){
var ajx = new ajxQuery({
'post' : '&videoID=' + streamLink[2],
'url' : SYS_URL + 'youtube',
'retorno' : 'json',
'onCarregando' : function(){},
'onRetorno' : function(json){
if(json[0]){
$('#stream-link-status').attr('value',1);
$('#stream-link').attr('value',streamLink[1]);
$('#stream-link-type').attr('value','YOUTUBE');
$('#stream-link-thumb').attr('value',json[2]);
$('#stream-link-title').attr('value',json[0]);
$('#stream-link-description').attr('value',json[1]);
$('#stream-link-embed').attr('value',json[3]);
$('#link-thumb').attr('src',json[2]);
$('#link-titulo').text(json[0]);
$('#link-description').text(json[1]);
$('#cont-stream-link').show();
}
}
});
ajx.conectar();
}
}
})
I also found in another file . js separate:
function getURL(text) {
var patternLink = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var patternYoutube = /youtu(be.com|.b)(\/v\/|\/watch\\?v=|e\/|\/watch(.+)v=)(.{11})/;
var er = new RegExp(patternLink);
var arLink = er.exec(text);
if(arLink){
var er = new RegExp(patternYoutube);
var arYoutube = er.exec(arLink[0]);
if(arYoutube){
return [
'YOUTUBE',
arLink[0],
arYoutube[4]
];
}else{
return [
'LINK',
arLink[0],
null
];
}
return true;
}else{
return false;
}
}
and:
/**************** START STREAM ********************/
Function openVideo(newsID,param){
var obj = $("#item-"+newsID+" .link-thumb");
$(obj).html("");
$(obj).css("paddingBottom","10px");
switch(param[0]){
case "YOUTUBE":
$(obj).append("<iframe width='408' height='230' src='http://www.youtube.com/embed/"+param[1]+"?wmode=transparent' frameborder='0' allowfullscreen></iframe>");
break;
}
}
Function streamCapture(){
var streamLink = getURL($("#stream-text").val());
if(streamLink && !$('#stream-link-status').attr('value')){
if(streamLink[0] == 'YOUTUBE'){
var ajx = new ajxQuery({
'post' : '&videoID=' + streamLink[2],
'url' : SYS_URL + 'youtube',
'retorno' : 'json',
'onCarregando' : function(){
$('#content-loading').show();
},
'onRetorno' : function(json){
if(json[0]){
$('#stream-link-status').attr('value',1);
$('#stream-link').attr('value',streamLink[1]);
$('#stream-link-type').attr('value','YOUTUBE');
$('#stream-link-thumb').attr('value',json[2]);
$('#stream-link-title').attr('value',json[0]);
$('#stream-link-description').attr('value',json[1]);
$('#stream-link-embed').attr('value',json[3]);
$('#link-thumb').attr('src',json[2]);
$('#link-titulo').text(json[0]);
$('#link-description').text(json[1]);
$('#link').show();
}
$('#content-loading').hide();
}
});
ajx.conectar();
}else{
}
}
}
Function closeLink(){
$(
'#stream-link-status,'+
'#stream-link,'+
'#stream-link-type,'+
'#stream-link-Thumb,'+
'#stream-link-title,'+
'#stream-link-Description,'+
'#stream-link-embed'
). attr("value","");
$('#link'). slideup();
$('#cont-addVideoPublish'). show();
}
How can I use these files to do the same as the video? Thank you.
At first, I don’t recommend using other people’s code without authorization, and besides, it’s not easy to use code without comment. I think it would be easier to start from Zero by following the application setup tutorial and using some sdk for javascript. As you go, you could post the code to see progress. Looking at the requirement, you need to follow the steps to configure your application using google services. After that use the method
videos/list
API to fetch everything you need: title, description and video thumbnails.– Wakim
This link (https://developers.google.com/youtube/v3/docs/videos/list?hl=pt-br#Try-it) allows you to test the usage of the api. Fill in the part field with the value "snippet" and the
id
of the video you want. In the reply you will see all the information you need.– Wakim