Showing
1 changed file
with
28 additions
and
0 deletions
Search.js
0 → 100644
| 1 | +var Youtube = require('youtube-node'); | ||
| 2 | +var youtube = new Youtube(); | ||
| 3 | + | ||
| 4 | +var word = '백종원 레시피'; // 검색어 지정 | ||
| 5 | +var limit = 10; // 출력 갯수 | ||
| 6 | + | ||
| 7 | +youtube.setKey('AIzaSyAsKr_oWGZIBbL5tLdIl98Lf9Pzqj8jX4o'); // API 키 입력 | ||
| 8 | + | ||
| 9 | +youtube.addParam('order', 'rating'); // 평점 순으로 정렬 | ||
| 10 | +youtube.addParam('type', 'video'); // 타입 지정 | ||
| 11 | +youtube.addParam('videoLicense', 'creativeCommon'); // 크리에이티브 커먼즈 아이템만 불러옴 | ||
| 12 | + | ||
| 13 | +youtube.search(word, limit, function (err, result) { // 검색 실행 | ||
| 14 | + if (err) { console.log(err); return; } // 에러일 경우 에러공지하고 빠져나감 | ||
| 15 | + | ||
| 16 | + console.log(JSON.stringify(result, null, 2)); // 받아온 전체 리스트 출력 | ||
| 17 | + | ||
| 18 | + var items = result["items"]; // 결과 중 items 항목만 가져옴 | ||
| 19 | + for (var i in items) { | ||
| 20 | + var it = items[i]; | ||
| 21 | + var title = it["snippet"]["title"]; | ||
| 22 | + var video_id = it["id"]["videoId"]; | ||
| 23 | + var url = "https://www.youtube.com/watch?v=" + video_id; | ||
| 24 | + console.log("제목 : " + title); | ||
| 25 | + console.log("URL : " + url); | ||
| 26 | + console.log("-----------"); | ||
| 27 | + } | ||
| 28 | +}); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment