ytjs
v1.1.0
Published
Youtube API v3 Universal Javascript Library for nodeJS, AMD and browser which provides easy API
Downloads
21
Maintainers
Readme
YTjs
Youtube API v3 Universal Javascript Library for nodeJS, AMD and browser which provides easy API
No Jquery needed.
How to get Youtube API Key
Node JS
Example
var youtube = require('ytjs')("API KEY");
youtube.getdata({ videoId: "TlgqWeuhJj4"},function(err, result){
if(err) {
console.log(err);
return false;
}
console.log(result);
});
Browser
include yt.js
<script type="text/javascript" src="yt.js" ></script>
Initalize the library and get Data
var youtube = $youtube("API KEY");
youtube.getdata({ videoId: "TlgqWeuhJj4" },function(err, result){
if(err) {
console.log(err);
return false;
}
console.log(result);
});
youtube.getdata({ videoId: "PMr2NRPdpH4"}, function(err, result){
if(err) {
console.log(err);
return false;
}
console.log(result);
});
Methods Available
- getdata
- search
- getComments
- getRelatedVideos
get video data (getdata)
youtube.getdata({ videoId: "TlgqWeuhJj4" },function(err, result){
if(err) {
console.log(err);
return false;
}
console.log(result);
});
Searching for Videos (search)
youtube.search({keyword: "rihanna love", fullResults: 1, order: "relevance"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
Comments (getComments)
youtube.getComments({videoId: "PMr2NRPdpH4"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
Related videos (getRelatedVideos)
youtube.getRelatedVideos({videoId: "PMr2NRPdpH4"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
Options
getdata
- videoId : youtube video id
- part: "snippet,statistics,contentDetails" // you can pass either of three orcombination or all
output format (getdata)
You can get wide variety of data from getdata
method and always youtube original data can be referred in raw
"title":
"description":
"rating":
"views":"",
"publishedAt":
"dthumbnail":
"mthumbnail":
"hthumbnail":
"sthumbnail":
"categoryId":
"channelTitle":
"videoId":"",
"duration":
"mins":
"hr":
"secs":
"dimension":
definition":
caption":
licensedContent":
"viewCount":
"likeCount":
"dislikeCount":
"favoriteCount":
"commentCount":
"kind":
"channelId":
"thumbnails":{}
"tags":{}
"liveBroadcastContent":"none"
"localized":{}
"projection":
"raw":{}
search
- keyword : keyword for search
- order: "relevance" // date, rating, viewCount, videoCount, title
- type : "basic" // "detailed" will provide additional information for each search video
- navigate : "next" // would render next set of results as youtube only allows 50 videos at a time
output format (search)
You can get wide variety of data from search
method. Results of search will be returned in videos
array and always youtube original data can be referred in raw
"videos" : []
nextPageToken:
prevPageToken:
kind:
comments
youtube.getComments({videoId: "PMr2NRPdpH4"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
nextComments();
});
// next set of comments
function nextComments() {
youtube.getComments({videoId: "PMr2NRPdpH4", navigate: "next"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
}
output format (getComments)
You can get wide variety of data from getComments
method. Results of comments will be returned in items
array and always youtube original data can be referred in raw
items
array item usually have different values such as textDisplay
, authorDisplayName
, authorProfileImageUrl
, likeCount
etc
items : []
nextPageToken:
prevPageToken:
resultsPerPage:
raw:
Related videos (getRelatedVideos)
youtube.getRelatedVideos({videoId: "PMr2NRPdpH4"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
output format (getRelatedVideos)
You can get wide variety of data from getRelatedVideos
method. Results of related videos will be returned in videos
array and always youtube original data can be referred in raw
"videos" : []
nextPageToken:
prevPageToken:
kind:
debug mode
Debug mode will print details to your console. you can enable debug mode during intialization by passing true
var youtube = $youtube("API KEY", true);
Implemented Features
[ x ] get Video Data
[ x ] search for videos
[ x ] get Comments
[ x ] npm module
[ x ] related videos
Upcoming Plan
[ ] Please open an issue