better-youtube-api
Advanced tools
Comparing version 2.1.4 to 2.1.5
@@ -22,22 +22,41 @@ "use strict"; | ||
_init(data) { | ||
if (data.kind === 'youtube#channel' && data.status.isLinked) { | ||
/* istanbul ignore next */ | ||
if (data.kind === 'youtube#channel' && (!data.status || data.status.isLinked)) { | ||
const channel = data; | ||
this.id = channel.id; | ||
this.country = channel.snippet.country; | ||
this.language = channel.snippet.defaultLanguage; | ||
this.views = Number(channel.statistics.viewCount); | ||
this.commentCount = Number(channel.statistics.commentCount); | ||
this.banners = channel.brandingSettings.image; | ||
// Unknown behavior | ||
/* istanbul ignore next */ | ||
if (channel.brandingSettings.channel) { | ||
this.keywords = channel.brandingSettings.channel.keywords ? channel.brandingSettings.channel.keywords.split(' ') : []; | ||
this.featuredChannels = channel.brandingSettings.channel.featuredChannelsUrls ? | ||
channel.brandingSettings.channel.featuredChannelsUrls.map(id => `https://www.youtube.com/channel/${id}`) : []; | ||
if (channel.snippet) { | ||
this.country = channel.snippet.country; | ||
this.language = channel.snippet.defaultLanguage; | ||
} | ||
if (!channel.statistics.hiddenSubscriberCount) { | ||
this.subCount = Number(channel.statistics.subscriberCount); | ||
/* istanbul ignore next */ | ||
if (channel.statistics) { | ||
this.views = Number(channel.statistics.viewCount); | ||
this.commentCount = Number(channel.statistics.commentCount); | ||
if (!channel.statistics.hiddenSubscriberCount) { | ||
this.subCount = Number(channel.statistics.subscriberCount); | ||
} | ||
else { | ||
this.subCount = -1; | ||
} | ||
} | ||
else { | ||
this.subCount = -1; | ||
/* istanbul ignore next */ | ||
if (channel.brandingSettings) { | ||
this.banners = channel.brandingSettings.image; | ||
// Unknown behavior | ||
/* istanbul ignore next */ | ||
if (channel.brandingSettings.channel) { | ||
this.keywords = []; | ||
if (channel.brandingSettings.channel.keywords) { | ||
// Split by spaces but keep quotations intact | ||
const broken = channel.brandingSettings.channel.keywords.split(/( )(?=(?:[^"]*"[^"]*")*[^"]*$)/i); | ||
for (let i = 0; i < broken.length; i++) { | ||
if (i % 2 === 0) { | ||
this.keywords.push(broken[i].replace(/(^"|"$)/gi, '')); | ||
} | ||
} | ||
} | ||
this.featuredChannels = channel.brandingSettings.channel.featuredChannelsUrls ? | ||
channel.brandingSettings.channel.featuredChannelsUrls.map(id => `https://www.youtube.com/channel/${id}`) : []; | ||
} | ||
} | ||
@@ -47,5 +66,8 @@ } | ||
this.id = data.id.channelId; | ||
// Impossible to test | ||
/* istanbul ignore next */ | ||
this.liveStatus = data.snippet.liveBroadcastContent !== 'none' ? data.snippet.liveBroadcastContent : false; | ||
if (data.snippet) { | ||
// Impossible to test | ||
/* istanbul ignore next */ | ||
this.liveStatus = data.snippet.liveBroadcastContent !== 'none' ? data.snippet.liveBroadcastContent : false; | ||
} | ||
} | ||
@@ -55,7 +77,10 @@ else { | ||
} | ||
/* istanbul ignore next */ | ||
if (data.snippet) { | ||
this.profilePictures = data.snippet.thumbnails; | ||
this.dateCreated = new Date(data.snippet.publishedAt); | ||
this.name = data.snippet.title; | ||
this.about = data.snippet.description; | ||
} | ||
this.url = `https://youtube.com/channel/${this.id}`; | ||
this.profilePictures = data.snippet.thumbnails; | ||
this.dateCreated = new Date(data.snippet.publishedAt); | ||
this.name = data.snippet.title; | ||
this.about = data.snippet.description; | ||
this.full = data.kind === 'youtube#channel'; | ||
@@ -62,0 +87,0 @@ } |
@@ -27,19 +27,22 @@ "use strict"; | ||
const comment = data; | ||
/* istanbul ignore next */ | ||
if (comment.snippet) { | ||
this.author = { | ||
username: comment.snippet.authorDisplayName, | ||
avatar: comment.snippet.authorProfileImageUrl, | ||
channelId: comment.snippet.authorChannelId.value, | ||
channelUrl: comment.snippet.authorChannelUrl | ||
}; | ||
this.text = { | ||
displayed: comment.snippet.textDisplay, | ||
original: comment.snippet.textOriginal | ||
}; | ||
this.rateable = comment.snippet.canRate; | ||
this.popular = comment.snippet.likeCount >= 100; | ||
this.likes = comment.snippet.likeCount; | ||
this.datePublished = comment.snippet.publishedAt; | ||
this.dateEdited = comment.snippet.updatedAt; | ||
this.parentId = comment.snippet.parentId ? comment.snippet.parentId : comment.snippet.videoId ? comment.snippet.videoId : comment.snippet.channelId; | ||
} | ||
this.id = comment.id; | ||
this.author = { | ||
username: comment.snippet.authorDisplayName, | ||
avatar: comment.snippet.authorProfileImageUrl, | ||
channelId: comment.snippet.authorChannelId.value, | ||
channelUrl: comment.snippet.authorChannelUrl | ||
}; | ||
this.text = { | ||
displayed: comment.snippet.textDisplay, | ||
original: comment.snippet.textOriginal | ||
}; | ||
this.rateable = comment.snippet.canRate; | ||
this.popular = comment.snippet.likeCount >= 100; | ||
this.likes = comment.snippet.likeCount; | ||
this.datePublished = comment.snippet.publishedAt; | ||
this.dateEdited = comment.snippet.updatedAt; | ||
this.parentId = comment.snippet.parentId ? comment.snippet.parentId : comment.snippet.videoId ? comment.snippet.videoId : comment.snippet.channelId; | ||
if (this.parentId) { | ||
@@ -46,0 +49,0 @@ this.url = 'https://youtube.com/' + (type === 'channel' ? `channel/${this.parentId}/discussion?lc=${this.id}` : `watch?v=${this.parentId}&lc=${this.id}`); |
@@ -25,5 +25,8 @@ "use strict"; | ||
this.id = playlist.id; | ||
this.tags = playlist.snippet.tags; | ||
this.length = playlist.contentDetails.itemCount; | ||
this.embedHtml = playlist.player.embedHtml; | ||
/* istanbul ignore next */ | ||
this.tags = playlist.snippet ? playlist.snippet.tags : undefined; | ||
/* istanbul ignore next */ | ||
this.length = playlist.contentDetails ? playlist.contentDetails.itemCount : undefined; | ||
/* istanbul ignore next */ | ||
this.embedHtml = playlist.player ? playlist.player.embedHtml : undefined; | ||
} | ||
@@ -36,7 +39,10 @@ else if (data.kind === 'youtube#searchResult') { | ||
} | ||
this.title = data.snippet.title; | ||
this.creatorId = data.snippet.channelId; | ||
/* istanbul ignore next */ | ||
if (data.snippet) { | ||
this.title = data.snippet.title; | ||
this.creatorId = data.snippet.channelId; | ||
this.dateCreated = new Date(data.snippet.publishedAt); | ||
this.thumbnails = data.snippet.thumbnails; | ||
} | ||
this.url = `https://youtube.com/playlist?list=${this.id}`; | ||
this.dateCreated = new Date(data.snippet.publishedAt); | ||
this.thumbnails = data.snippet.thumbnails; | ||
this.full = data.kind === 'youtube#playlist'; | ||
@@ -43,0 +49,0 @@ } |
@@ -25,8 +25,14 @@ "use strict"; | ||
const video = data; | ||
this._length = util_1.parseIsoDuration(video.contentDetails.duration); | ||
this.minutes = (this._length.hours * 60) + this._length.minutes; | ||
this.seconds = this._length.seconds; | ||
this.likes = Number(video.statistics.likeCount); | ||
this.dislikes = Number(video.statistics.dislikeCount); | ||
this.views = Number(video.statistics.viewCount); | ||
/* istanbul ignore next */ | ||
if (video.contentDetails) { | ||
this._length = util_1.parseIsoDuration(video.contentDetails.duration); | ||
this.minutes = (this._length.hours * 60) + this._length.minutes; | ||
this.seconds = this._length.seconds; | ||
} | ||
/* istanbul ignore next */ | ||
if (video.statistics) { | ||
this.likes = Number(video.statistics.likeCount); | ||
this.dislikes = Number(video.statistics.dislikeCount); | ||
this.views = Number(video.statistics.viewCount); | ||
} | ||
this.id = video.id; | ||
@@ -44,13 +50,16 @@ } | ||
} | ||
this.title = data.snippet.title; | ||
this.description = data.snippet.description; | ||
this.thumbnails = data.snippet.thumbnails; | ||
this.datePublished = new Date(data.snippet.publishedAt); | ||
this.channelId = data.snippet.channelId; | ||
/* istanbul ignore next */ | ||
if (data.snippet) { | ||
this.title = data.snippet.title; | ||
this.description = data.snippet.description; | ||
this.thumbnails = data.snippet.thumbnails; | ||
this.datePublished = new Date(data.snippet.publishedAt); | ||
this.channelId = data.snippet.channelId; | ||
// Impossible to test | ||
/* istanbul ignore next */ | ||
this.liveStatus = data.snippet.liveBroadcastContent !== 'none' ? data.snippet.liveBroadcastContent : false; | ||
} | ||
this.full = data.kind === 'youtube#video'; | ||
this.url = `https://youtube.com/watch?v=${this.id}`; | ||
this.shortUrl = `https://youtu.be/${this.id}`; | ||
// Impossible to test | ||
/* istanbul ignore next */ | ||
this.liveStatus = data.snippet.liveBroadcastContent !== 'none' ? data.snippet.liveBroadcastContent : false; | ||
return this; | ||
@@ -57,0 +66,0 @@ } |
@@ -30,3 +30,3 @@ "use strict"; | ||
*/ | ||
constructor(token, options = { cache: true, cacheTTL: 600, cacheCheckInterval: 600, cacheSearches: false }) { | ||
constructor(token, options = { cache: true, cacheTTL: 600, cacheCheckInterval: 600, cacheSearches: true }) { | ||
this.token = token; | ||
@@ -254,6 +254,7 @@ this.oauth = new oauth_1.OAuth(this); | ||
}); | ||
const toReturn = { results: items, prevPageToken: results.prevPageToken, nextPageToken: results.nextPageToken }; | ||
if (this._shouldCache && this._cacheSearches) { | ||
this._cache(`search://${type}/"${searchTerm}"/${maxResults}/"${pageToken}"`, items); | ||
this._cache(`search://${type}/"${searchTerm}"/${maxResults}/"${pageToken}"`, toReturn); | ||
} | ||
return { results: items, prevPageToken: results.prevPageToken, nextPageToken: results.nextPageToken }; | ||
return toReturn; | ||
}); | ||
@@ -260,0 +261,0 @@ } |
{ | ||
"name": "better-youtube-api", | ||
"version": "2.1.4", | ||
"version": "2.1.5", | ||
"description": "A very easy to use promise-based Youtube Data v3 API.", | ||
@@ -5,0 +5,0 @@ "main": "out/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167412
2010