2017-01-25 1 views
-1

내 SEARCH_QUERY = 검색 예 :이 이 https://www.youtube.com/results?search_query=hangover+2009+trailer영화 트레일러 유튜브 SEARCH_QUERY 사람이 내가 처음 YouTube 동영상 링크 결과를 얻을 수있는 방법을 말씀 해주십시오 수

첫 번째 결과 링크는 다음과 같습니다 https://www.youtube.com/watch?v=tcdUhdOlz9M

수 아무도 jquery로 어떻게 할 수 있는지 말해 주시겠습니까? search_query를 기반으로 youtubes 영화 예고편 링크를 기꺼이 받아 볼 수 있습니다.

원인이 링크는 이후에 내 페이지에 표시하기 위해 iframe에서 사용할 수 있습니다.

<iframe width="560" height="315" src="https://www.youtube.com/embed/tcdUhdOlz9M" frameborder="0" allowfullscreen></iframe> 

고맙습니다! 기본적으로 검색 결과에 대한 독특한 뭔가를 찾을 :

+0

서버를 사용하십시오. 자신 만의 빌드 방법을 모르는 경우 [diff bot] (https://www.diffbot.com/dev/docs/article/)를 사용하십시오. – ymz

답변

0

당신은 아마 대신 유튜브 API 통합하려는 : https://developers.google.com/youtube/v3/docs/search/list

을하지만 당신은 당신이 위의 설명과 같이 수행하려는 경우, 해당 페이지를 얻을 수 다음 결과를 긁어 대상을 jquery 선택기로 지정한 다음 원하는 데이터를 요소에서 가져옵니다.

0

는 다음과 같은 시도 :

function searchByKeyword() { 
    var results = YouTube.Search.list('id,snippet', {q: 'hangover+2009+trailer', maxResults: 1}); 
    return results.items[0]; 
} 
1

그것은 간단합니다. 코드를 Youtube API와 통합하면 API (결과의 양, 날짜 등)를 사용하여 거의 모든 것을 설정할 수있는 결과와 같은 객체를 반환합니다. 그래서, 당신이 볼 수있는 것처럼 그것을 형성 할 수 있습니다.

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'); 
    }); 

당신은 유튜브 API, NodeJS와 익스프레스 here 간단한 프로젝트를 볼 수 있습니다

다음은 결과에 어떤 치료와 jQuery를 예입니다.