machinepack-youtubenodemachines/youtubeAPICalls.js
function formatVideosJson(videos, statistics) {
  var formatedVideos = []

  if (Array.isArray(videos)) {
    for (var i = 0; i < videos.length; i++) {
      var video = {
        "platform": "Youtube",
        "channel_id": videos[i].snippet.channelId,
        "channel_url": "",
        "channel_title": videos[i].snippet.channelTitle,
        "video_id": videos[i].id.videoId,
        "video_url": "",
        "video_embeded_url": "",
        "video_title": videos[i].snippet.title,
        "video_description": videos[i].snippet.description,
        "video_created_at": (new Date(videos[i].snippet.publishedAt).toISOString()),
        "video_thumbnail_url": videos[i].snippet.thumbnails.high.url,
        "video_view_count": "",
        "video_like_count": "",
        "video_dislike_count": "",
        "video_comment_count": ""
      };
      video.channel_url = "https://www.youtube.com/channel/" + video.channel_id;
      video.video_url = "https://www.youtube.com/watch?v=" + video.video_id;
      video.video_embeded_url = "https://www.youtube.com/embed/" + video.video_id;

      formatedVideos.push(video);
    }
  }

  // Add statistics
  if (Array.isArray(statistics)) {
    for (var i = 0; i < statistics.length; i++) {
      formatedVideos[i].video_view_count = statistics[i].statistics.viewCount;
      formatedVideos[i].video_like_count = statistics[i].statistics.likeCount;
      formatedVideos[i].video_dislike_count = statistics[i].statistics.dislikeCount;
      formatedVideos[i].video_comment_count = statistics[i].statistics.commentCount;
    }
  }

  return formatedVideos;
}
function formatVideosJson(videos, statistics) {
  var formatedVideos = []

  if (Array.isArray(videos)) {
    for (var i = 0; i < videos.length; i++) {
      var video = {
        "platform": "Youtube",
        "channel_id": videos[i].snippet.channelId,
        "channel_url": "",
        "channel_title": videos[i].snippet.channelTitle,
        "video_id": videos[i].id.videoId,
        "video_url": "",
        "video_embeded_url": "",
        "video_title": videos[i].snippet.title,
        "video_description": videos[i].snippet.description,
        "video_created_at": (new Date(videos[i].snippet.publishedAt).toISOString()),
        "video_thumbnail_url": videos[i].snippet.thumbnails.high.url,
        "video_view_count": "",
        "video_like_count": "",
        "video_dislike_count": "",
        "video_comment_count": ""
      };
      video.channel_url = "https://www.youtube.com/channel/" + video.channel_id;
      video.video_url = "https://www.youtube.com/watch?v=" + video.video_id;
      video.video_embeded_url = "https://www.youtube.com/embed/" + video.video_id;

      formatedVideos.push(video);
    }
  }

  // Add statistics
  if (Array.isArray(statistics)) {
    for (var i = 0; i < statistics.length; i++) {
      formatedVideos[i].video_view_count = statistics[i].statistics.viewCount;
      formatedVideos[i].video_like_count = statistics[i].statistics.likeCount;
      formatedVideos[i].video_dislike_count = statistics[i].statistics.dislikeCount;
      formatedVideos[i].video_comment_count = statistics[i].statistics.commentCount;
    }
  }

  return formatedVideos;
}
function formatVideosJson ( videos , statistics ) { var formatedVideos = [ ] if ( Array . isArray ( videos ) ) { for ( var i = 0 ; i < videos . length ; i ++ ) { var video = { "platform" : "Youtube" , "channel_id" : videos [ i ] . snippet . channelId , "channel_url" : "" , "channel_title" : videos [ i ] . snippet . channelTitle , "video_id" : videos [ i ] . id . videoId , "video_url" : "" , "video_embeded_url" : "" , "video_title" : videos [ i ] . snippet . title , "video_description" : videos [ i ] . snippet . description , "video_created_at" : ( new Date ( videos [ i ] . snippet . publishedAt ) . toISOString ( ) ) , "video_thumbnail_url" : videos [ i ] . snippet . thumbnails . high . url , "video_view_count" : "" , "video_like_count" : "" , "video_dislike_count" : "" , "video_comment_count" : "" } ; video . channel_url = "https://www.youtube.com/channel/" + video . channel_id ; video . video_url = "https://www.youtube.com/watch?v=" + video . video_id ; video . video_embeded_url = "https://www.youtube.com/embed/" + video . video_id ; formatedVideos . push ( video ) ; } } // Add statistics if ( Array . isArray ( statistics ) ) { for ( var i = 0 ; i < statistics . length ; i ++ ) { formatedVideos [ i ] . video_view_count = statistics [ i ] . statistics . viewCount ; formatedVideos [ i ] . video_like_count = statistics [ i ] . statistics . likeCount ; formatedVideos [ i ] . video_dislike_count = statistics [ i ] . statistics . dislikeCount ; formatedVideos [ i ] . video_comment_count = statistics [ i ] . statistics . commentCount ; } } return formatedVideos ; }
Format the JSON object containing the video data
Format the JSON object containing the video data