Playlist_Mood_Sad.js 1.17 KB
const { google } = require("googleapis");
var service = google.youtube('v3');

service.playlistItems.list({
    key: 'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518',
    part: 'snippet',
    fields: 'items(snippet(title,resourceId,thumbnails(high(url))))', //제목, VideoId, Thumbnail 이미지 정보.
    maxResults: 10,
    playlistId: 'PLfVO1GXBPp3vrR3ZcQFlCEC6oNdo_MQ_R'
}, function (err, response) {
    if (err) {
        console.log('The API returned an error: ', err);
        return;
    }

    var video = response.data.items;
    if (video.length == 0) {
        console.log('검색된 동영상이 없습니다.');
    } else {
        for (var i = 0; i < 10; i++) {
            console.log('{');
            console.log(JSON.stringify(response.data.items[i].snippet.title).replace(/\"/gi, ""));
            var a = JSON.stringify(response.data.items[i].snippet.resourceId.videoId);
            console.log('https://www.youtube.com/watch?v=' + a.replace(/\"/gi, ""));  //JSON stringify 큰따옴표 제거후 URL로 전환
            console.log(JSON.stringify(response.data.items[i].snippet.thumbnails.high.url).replace(/\"/gi, ""));
            console.log('}');
        }
    }
})