Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tanveerkhanwd's avatar

Can you please tell me how to get transcript from youtube api?

//HERE IS MY CODE:

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(){
    $("form").on("submit", function(e) {
      e.preventDefault();
      // prepare the request
      var request = gapi.client.youtube.search.list({
            part: "snippet",
            type: "video",
            videoEmbeddable: true,
            videoCaption:"any",
            q: encodeURIComponent($("#search").val()).replace(/%20/g, "+"),
            maxResults: 1,
            order: "viewCount",
            publishedAfter: "2015-01-01T00:00:00Z"
      });
      //execute the request
      request.execute(function(response) {
          var results = response.result;
          console.log(results);
          var html = '';
          $.each(results.items, function(index, item){
            html += '<div class="youtubeid col-sm-3 col-md-3 col-lg-3"><div class="card"><div class="embed-responsive embed-responsive-16by9">';
            html += '<iframe custAttr="'+item.id.videoId+'" custtitle="'+item.snippet.title+'" class="embed-responsive-item" src="//www.youtube.com/embed/'+item.id.videoId+'" allowfullscreen></iframe>';
            html += '</div><div class="card-body ytcard-text">'+item.snippet.title+'</div></div></div>';  
            $("#results").css("display","block").html(html);
          });
          
          var singleVhtml = '';
          $(".youtubeid").click(function(){
            $(".hidesearchcontainer").css("display","none");
            var videoId = $(this).find("iframe").attr("custAttr");
            var videoTitle = $(this).find("iframe").attr("custtitle");
            
            singleVhtml+= '<div class="col-sm-8 col-md-8 col-lg-8 col-xl-8" ><div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" src="//www.youtube.com/embed/'+videoId+'" allowfullscreen></iframe></div>';
            singleVhtml+= '<div class="row"><div class="ytcard-text title col-sm-8 col-md-8 col-lg-8 col-xl-8">'+videoTitle+'</div><div class="icon col-sm-4 col-md-4 col-lg-4 col-xl-4">';
            singleVhtml+= '<i class="fa fa-thumbs-o-up"></i>12k<i class="fa fa-thumbs-o-down"></i>1k<i class="fa fa-share"></i>SHARE<i class="fa fa-list"></i>SAVE<i class="fa fa-ellipsis-h"></i></div></div></div>';
            $("#showvideodata").css("display","block").html(singleVhtml);
          });
          resetVideoHeight();
       });
    });
    
    $(window).on("resize", resetVideoHeight);
});

function resetVideoHeight() {
    $(".video").css("height", $(".results").width() * 9/16);
}

function init() { 
    //AIzaSyA7WkJ27_jWV03d_fb0w9mfa2lxfGIAtqU  AIzaSyB1l24kUu6gaBEjItEyvliG8sw6D2TEbVw
    gapi.client.setApiKey("AIzaSyA7WkJ27_jWV03d_fb0w9mfa2lxfGIAtqU");
    gapi.client.load("youtube", "v3", function() {
        // yt api is ready
    });
}
0 likes
2 replies
tanveerkhanwd's avatar

through this i am getting only title and video_id and description

tanveerkhanwd's avatar

// i get it but its working on some videos so if any one has another code to retrive so please share

            type: "POST",
            url: "https://video.google.com/timedtext?lang=en&v="+item.id.videoId
            }).done(function (response) {
                console.log(response);
            }).fail(function (response) {
                console.log();
            });

Please or to participate in this conversation.