Comparing version 5.0.0 to 6.0.0
@@ -77,4 +77,3 @@ "use strict"; | ||
snippet: { | ||
type: undefined, | ||
style: undefined | ||
type: undefined | ||
} | ||
@@ -81,0 +80,0 @@ }; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,3 +8,85 @@ exports.Caption = void 0; | ||
class Caption { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'i18nRegions'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,snippet(*))'; | ||
/** | ||
* The YouTube object that created this caption track object. | ||
*/ | ||
youtube; | ||
/** | ||
* Whether or not this is a full caption track object. | ||
*/ | ||
full = true; | ||
/** | ||
* The raw data of this caption track. | ||
*/ | ||
data; | ||
/** | ||
* The ID of this caption track. | ||
*/ | ||
id; | ||
/** | ||
* The ID of the [[Video]] that this caption track is for. | ||
*/ | ||
videoId; | ||
/** | ||
* When this caption track was last updated. | ||
*/ | ||
lastUpdated; | ||
/** | ||
* The kind of caption track this is (automatic speech recognition, forced due to foreign language, or standard). | ||
*/ | ||
kind; | ||
/** | ||
* The language that this caption track is written in. | ||
*/ | ||
language; | ||
/** | ||
* The name of this caption track. | ||
*/ | ||
name; | ||
/** | ||
* Whether the audio is a commentary/descriptive (alternate audio tracks), the primary audio track, or unknown. | ||
*/ | ||
audioType; | ||
/** | ||
* Whether or not this caption track is for the deaf/hard of hearing. | ||
*/ | ||
closedCaptions; | ||
/** | ||
* Whether or not this caption track uses large text for the vision-impaired. | ||
*/ | ||
large; | ||
/** | ||
* Whether or not this caption track is written at a third-grade level (for language learners). | ||
*/ | ||
easyReader; | ||
/** | ||
* Whether or not this caption track is a draft. If so, it won't be shown to users. | ||
*/ | ||
draft; | ||
/** | ||
* Whether or not this caption track has been autosynced to the audio by YouTube. | ||
*/ | ||
autoSynced; | ||
/** | ||
* The processing status of the caption track. | ||
*/ | ||
status; | ||
/** | ||
* If [[Caption.status]] is `failed`, then this is populated with the reason failure. | ||
*/ | ||
// Must fail for this property to be populated | ||
/* istanbul ignore next */ | ||
failureReason; | ||
constructor(youtube, data, full = true) { | ||
this.youtube = youtube; | ||
@@ -32,3 +105,2 @@ this.data = data; | ||
this.id = caption.id; | ||
this.full = true; | ||
/* istanbul ignore next */ | ||
@@ -50,6 +122,2 @@ if (caption.snippet) { | ||
} | ||
else { | ||
/* istanbul ignore next */ | ||
this.full = false; | ||
} | ||
} | ||
@@ -62,7 +130,5 @@ /** | ||
/* istanbul ignore next */ | ||
fetch() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const caption = yield this.youtube.oauth.getCaption(this.videoId, this.id); | ||
return Object.assign(this, caption); | ||
}); | ||
async fetch() { | ||
const caption = await this.youtube.oauth.getCaption(this.videoId, this.id); | ||
return Object.assign(this, caption); | ||
} | ||
@@ -76,7 +142,5 @@ /** | ||
/* istanbul ignore next */ | ||
update(track, draft = null) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const newCaption = yield this.youtube.oauth.updateCaption(this.id, track, draft); | ||
return Object.assign(this, Object.assign(Object.assign({}, newCaption), { full: true })); | ||
}); | ||
async update(track, draft = null) { | ||
const newCaption = await this.youtube.oauth.updateCaption(this.id, track, draft); | ||
return Object.assign(this, { ...newCaption, full: true }); | ||
} | ||
@@ -103,15 +167,3 @@ /** | ||
exports.Caption = Caption; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
Caption.endpoint = 'i18nRegions'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
Caption.part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
Caption.fields = 'items(kind,id,snippet(*))'; | ||
//# sourceMappingURL=caption.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ChannelSection = void 0; | ||
/** | ||
* A YouTube channel section. | ||
* A YouTube [[Channel]] section. | ||
*/ | ||
class ChannelSection { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'channelSections'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet,contentDetails,localizations,targeting'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,contentDetails,localizations,snippet,targeting)'; | ||
/** | ||
* The YouTube object that created this channel section object. | ||
*/ | ||
youtube; | ||
/** | ||
* Whether or not this a full channel section object. | ||
*/ | ||
full = true; | ||
/** | ||
* The raw data of this channel section. | ||
*/ | ||
data; | ||
/** | ||
* The name of this channel section. | ||
*/ | ||
name; | ||
/** | ||
* The type of this channel section. | ||
*/ | ||
type; | ||
/** | ||
* The ID of the channel that created this channel section. | ||
*/ | ||
channelId; | ||
/** | ||
* The zero-based position of this channel section on the channel page. | ||
*/ | ||
position; | ||
/** | ||
* The IDs of the playlists in this channel section. Undefined if there aren't any. | ||
*/ | ||
playlistIds; | ||
/** | ||
* The IDs of the channels in this channel section. Undefined if there aren't any. | ||
*/ | ||
channelIds; | ||
/** | ||
* The playlists in the channel section. Only available after calling [[ChannelSection.fetchPlaylists]]. | ||
*/ | ||
playlists; | ||
/** | ||
* The channels in the channel section. Only available after calling [[ChannelSection.fetchChannels]]. | ||
*/ | ||
channels; | ||
/** | ||
* The ID of this channel section. | ||
*/ | ||
id; | ||
constructor(youtube, data, full = true) { | ||
this.youtube = youtube; | ||
@@ -37,10 +88,3 @@ this.data = data; | ||
this.position = section.snippet.position; | ||
this.language = section.snippet.defaultLanguage; | ||
this.style = section.snippet.style; | ||
/* istanbul ignore next */ | ||
this.localizedName = section.snippet.localized ? section.snippet.localized.title : undefined; | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
/* istanbul ignore next */ | ||
@@ -51,19 +95,2 @@ if (section.contentDetails) { | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
/* istanbul ignore next */ | ||
if (section.localizations) { | ||
this.localizations = section.localizations; | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
/* istanbul ignore next */ | ||
if (section.targeting) { | ||
this.targeting = section.targeting; | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
} | ||
@@ -74,55 +101,37 @@ /** | ||
*/ | ||
fetch() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const section = yield this.youtube.getChannelSection(this.id); | ||
return Object.assign(this, section); | ||
}); | ||
async fetch(parts) { | ||
const section = await this.youtube.getChannelSection(this.id, parts); | ||
return Object.assign(this, section); | ||
} | ||
/** | ||
* Fetches the channel section's playlists and assigns them to the [[ChannelSection#playlists]] property. | ||
* Fetches the channel section's playlists and assigns them to the [[ChannelSection.playlists]] property. | ||
*/ | ||
fetchPlaylists() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.playlistIds) { | ||
return; | ||
} | ||
const playlists = []; | ||
for (let i = 0; i < this.playlistIds.length; i++) { | ||
playlists.push(yield this.youtube.getPlaylist(this.playlistIds[i])); | ||
} | ||
this.playlists = playlists; | ||
return this.playlists; | ||
}); | ||
async fetchPlaylists(parts) { | ||
if (!this.playlistIds) { | ||
return; | ||
} | ||
const playlists = []; | ||
for (let i = 0; i < this.playlistIds.length; i++) { | ||
playlists.push(await this.youtube.getPlaylist(this.playlistIds[i], parts)); | ||
} | ||
this.playlists = playlists; | ||
return this.playlists; | ||
} | ||
/** | ||
* Fetches the channel section's playlists and assigns them to the [[ChannelSection#playlists]] property. | ||
* Fetches the channel section's channels and assigns them to the [[ChannelSection.channels]] property. | ||
*/ | ||
fetchChannels() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.channelIds) { | ||
return; | ||
} | ||
const channels = []; | ||
for (let i = 0; i < this.channelIds.length; i++) { | ||
channels.push(yield this.youtube.getChannel(this.channelIds[i])); | ||
} | ||
this.channels = channels; | ||
return this.channels; | ||
}); | ||
async fetchChannels(parts) { | ||
if (!this.channelIds) { | ||
return; | ||
} | ||
const channels = []; | ||
for (let i = 0; i < this.channelIds.length; i++) { | ||
channels.push(await this.youtube.getChannel(this.channelIds[i], parts)); | ||
} | ||
this.channels = channels; | ||
return this.channels; | ||
} | ||
} | ||
exports.ChannelSection = ChannelSection; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
ChannelSection.endpoint = 'channelSections'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
ChannelSection.part = 'snippet,contentDetails,localizations,targeting'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
ChannelSection.fields = 'items(kind,id,contentDetails,localizations,snippet,targeting)'; | ||
//# sourceMappingURL=channel-section.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,5 +8,122 @@ exports.Channel = void 0; | ||
class Channel { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'channels'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet,contentDetails,statistics,status,brandingSettings'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,contentDetails(relatedPlaylists(uploads)),statistics(subscriberCount,commentCount,viewCount,hiddenSubscriberCount),' + | ||
'snippet(title,description,thumbnails,publishedAt,country,defaultLanguage),brandingSettings(image,channel(keywords,featuredChannelsUrls)),' + | ||
'status(isLinked,madeForKids,selfDeclaredMadeForKids))'; | ||
/** | ||
* The YouTube object that created this channel object. | ||
*/ | ||
youtube; | ||
/** | ||
* Whether or not this a full channel object. | ||
*/ | ||
full; | ||
/** | ||
* The raw data of this channel. | ||
*/ | ||
data; | ||
/** | ||
* The name of this channel. | ||
*/ | ||
name; | ||
/** | ||
* The description of this channel. | ||
*/ | ||
about; | ||
/** | ||
* The ID of this channel. | ||
*/ | ||
id; | ||
/** | ||
* The country this channel is based in. | ||
*/ | ||
country; | ||
/** | ||
* The url of the channel. | ||
*/ | ||
url; | ||
/** | ||
* This channel's custom URL, if they have one. | ||
*/ | ||
customUrl; | ||
/** | ||
* This channel's profile pictures. | ||
*/ | ||
profilePictures; | ||
/** | ||
* The date this channel was created. | ||
*/ | ||
dateCreated; | ||
/** | ||
* The default language for this channel's uploads. | ||
*/ | ||
language; | ||
/** | ||
* This channel's view count. | ||
*/ | ||
views; | ||
/** | ||
* This channel's keywords. | ||
*/ | ||
keywords; | ||
/** | ||
* The channel's uploads. Only available after calling [[Channel.fetchVideos]] | ||
*/ | ||
videos; | ||
/** | ||
* The number of subscribers this channel has. `-1` if the subcount is hidden. | ||
*/ | ||
subCount; | ||
/** | ||
* This channel's comment count. | ||
* @deprecated See https://developers.google.com/youtube/v3/docs/channels#statistics.commentCount | ||
*/ | ||
commentCount; | ||
/** | ||
* The channel's comments. Only defined when [[Channel.fetchComments]] is called. | ||
*/ | ||
comments; | ||
/** | ||
* The URLs of all of this channel's featured channels. This property is broken for some channels. | ||
*/ | ||
/* istanbul ignore next */ | ||
featuredChannels; | ||
/** | ||
* The channel's playlists. Only defined when [[Channel.fetchPlaylists]] is called. | ||
*/ | ||
playlists; | ||
/** | ||
* The channel's subscriptions. Only defined when [[Channel.fetchSubscriptions]] is called. | ||
*/ | ||
subscriptions; | ||
/** | ||
* The channel's sections. Only defined when [[Channel.fetchSections]] is called. | ||
*/ | ||
sections; | ||
/** | ||
* Only set if the channel is a search result. | ||
* | ||
* If the channel has an ongoing livestream, this is `live`. | ||
* If the channel has an upcoming livestream, this is `upcoming`. | ||
* If the channel has neither an ongoing nor upcoming livestream, this is `false`. | ||
*/ | ||
liveStatus; | ||
/** | ||
* Properties to do with videos made for children. | ||
*/ | ||
kids; | ||
constructor(youtube, data, full = false) { | ||
this.youtube = youtube; | ||
this.data = data; | ||
this.full = full; | ||
this._init(data); | ||
@@ -27,5 +135,5 @@ } | ||
_init(data) { | ||
const channel = data; | ||
/* istanbul ignore next */ | ||
if (data.kind === 'youtube#channel' && (!data.status || data.status.isLinked)) { | ||
const channel = data; | ||
if (data.kind === 'youtube#channel') { | ||
this.id = channel.id; | ||
@@ -37,5 +145,2 @@ /* istanbul ignore next */ | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
/* istanbul ignore next */ | ||
@@ -52,5 +157,2 @@ if (channel.statistics) { | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
if (channel.status) { | ||
@@ -62,5 +164,2 @@ this.kids = { | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
/* istanbul ignore next */ | ||
@@ -87,29 +186,22 @@ if (channel.brandingSettings) { | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
} | ||
else if (data.kind === 'youtube#searchResult') { | ||
this.full = false; | ||
this.id = data.id.channelId; | ||
else if (channel.kind === 'youtube#searchResult') { | ||
this.id = channel.id?.channelId ?? channel.snippet?.channelId; | ||
/* istanbul ignore next */ | ||
if (data.snippet) { | ||
if (channel.snippet) { | ||
// Impossible to test | ||
/* istanbul ignore next */ | ||
this.liveStatus = data.snippet.liveBroadcastContent !== 'none' ? data.snippet.liveBroadcastContent : false; | ||
this.liveStatus = channel.snippet.liveBroadcastContent !== 'none' ? channel.snippet.liveBroadcastContent : false; | ||
} | ||
} | ||
else { | ||
throw new Error(`Invalid channel type: ${data.kind}`); | ||
throw new Error(`Invalid channel type: ${channel.kind}`); | ||
} | ||
/* 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; | ||
if (channel.snippet) { | ||
this.profilePictures = channel.snippet.thumbnails; | ||
this.dateCreated = new Date(channel.snippet.publishedAt); | ||
this.name = channel.snippet.title; | ||
this.about = channel.snippet.description; | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
this.url = `https://youtube.com/channel/${this.id}`; | ||
@@ -123,13 +215,11 @@ } | ||
/* istanbul ignore next */ | ||
postComment(text) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const comment = yield this.youtube.oauth.postComment(text, this.id); | ||
if (this.comments !== undefined) { | ||
this.comments.push(comment); | ||
} | ||
else { | ||
this.comments = [comment]; | ||
} | ||
return comment; | ||
}); | ||
async postComment(text) { | ||
const comment = await this.youtube.oauth.postComment(text, this.id); | ||
if (this.comments !== undefined) { | ||
this.comments.push(comment); | ||
} | ||
else { | ||
this.comments = [comment]; | ||
} | ||
return comment; | ||
} | ||
@@ -140,60 +230,50 @@ /** | ||
*/ | ||
fetch() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const channel = yield this.youtube.getChannel(this.id); | ||
return Object.assign(this, channel); | ||
}); | ||
async fetch(parts) { | ||
const channel = await this.youtube.getChannel(this.id, parts); | ||
return Object.assign(this, channel); | ||
} | ||
/** | ||
* Fetches the channel's videos and assigns them to the `Channel#videos` property. | ||
* Fetches the channel's playlist of uploads and assigns it to the [[Channel.videos]] property. | ||
*/ | ||
fetchVideos() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!(this.data.contentDetails)) { | ||
yield this.fetch(); | ||
} | ||
const videos = yield this.youtube.getPlaylist(this.data.contentDetails.relatedPlaylists.uploads); | ||
this.videos = videos; | ||
return this.videos; | ||
}); | ||
async fetchVideos(parts) { | ||
if (!(this.data.contentDetails)) { | ||
await this.fetch(['contentDetails']); | ||
} | ||
const videos = await this.youtube.getPlaylist(this.data.contentDetails.relatedPlaylists.uploads, parts); | ||
this.videos = videos; | ||
return this.videos; | ||
} | ||
/** | ||
* Fetches the channel's discussion tab comments and assigns them to Channel#comments. | ||
* @param maxResults The maximum amount of comments to fetch | ||
* @deprecated See https://support.google.com/youtube/thread/130882091?hl=en&msgid=131295194 | ||
* Fetches the channel's discussion tab comments and assigns them to [[Channel.comments]]. | ||
* @param pages The number of pages of comments to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchComments(maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.comments = yield this.youtube.getChannelComments(this.id, maxResults); | ||
return this.comments; | ||
}); | ||
/* istanbul ignore next */ | ||
async fetchComments(pages, parts) { | ||
this.comments = await this.youtube.getChannelComments(this.id, { pages }, parts); | ||
return this.comments; | ||
} | ||
/** | ||
* Fetches the channel's playlists and assigns them to Channel#playlists. | ||
* @param maxResults The maximum amount of playlists to fetch | ||
* Fetches the channel's playlists and assigns them to [[Channel.playlists]]. | ||
* @param pages The number of pages of playlists to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchPlaylists(maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.playlists = yield this.youtube.getChannelPlaylists(this.id, maxResults); | ||
return this.playlists; | ||
}); | ||
async fetchPlaylists(pages, parts) { | ||
this.playlists = await this.youtube.getChannelPlaylists(this.id, { pages }, parts); | ||
return this.playlists; | ||
} | ||
/** | ||
* Fetches the channel's subscriptions and assigns them to Channel#subscriptions. | ||
* @param maxResults The maximum amount of subscriptions to fetch | ||
* Fetches the channel's subscriptions and assigns them to [[Channel.subscriptions]]. | ||
* @param pages The number of pages of subscriptions to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
/* istanbul ignore next */ | ||
fetchSubscriptions(maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.subscriptions = yield this.youtube.getChannelSubscriptions(this.id, maxResults); | ||
return this.subscriptions; | ||
}); | ||
async fetchSubscriptions(pages, parts) { | ||
this.subscriptions = await this.youtube.getChannelSubscriptions(this.id, { pages }, parts); | ||
return this.subscriptions; | ||
} | ||
/** | ||
* Fetches the channel's sections and assigns them to [[Channel#sections]]. | ||
* Fetches the channel's sections and assigns them to [[Channel.sections]]. | ||
*/ | ||
fetchSections() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.sections = yield this.youtube.getChannelSections(this.id); | ||
return this.sections; | ||
}); | ||
async fetchSections(parts) { | ||
this.sections = await this.youtube.getChannelSections(this.id, parts); | ||
return this.sections; | ||
} | ||
@@ -261,34 +341,18 @@ /** | ||
/* istanbul ignore next */ | ||
setBanner(image) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.data.brandingSettings) { | ||
yield this.fetch(); | ||
} | ||
if (!this.data.brandingSettings) { | ||
return Promise.reject('Unable to fetch channel branding settings'); | ||
} | ||
if (!this.data.brandingSettings.image) { | ||
this.data.brandingSettings.image = {}; | ||
} | ||
this.data.brandingSettings.image.bannerExternalUrl = yield this.youtube.oauth.uploadChannelBanner(image); | ||
return this.youtube.oauth.updateChannelBranding(this.id, this.data.brandingSettings); | ||
}); | ||
async setBanner(image) { | ||
if (!this.data.brandingSettings) { | ||
await this.fetch(); | ||
} | ||
if (!this.data.brandingSettings) { | ||
return Promise.reject('Unable to fetch channel branding settings'); | ||
} | ||
if (!this.data.brandingSettings.image) { | ||
this.data.brandingSettings.image = {}; | ||
} | ||
this.data.brandingSettings.image.bannerExternalUrl = await this.youtube.oauth.uploadChannelBanner(image); | ||
return this.youtube.oauth.updateChannelBranding(this.id, this.data.brandingSettings); | ||
} | ||
} | ||
exports.Channel = Channel; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
Channel.endpoint = 'channels'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
Channel.part = 'snippet,contentDetails,statistics,status,brandingSettings'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
Channel.fields = 'items(kind,id,contentDetails(relatedPlaylists(uploads)),statistics(subscriberCount,commentCount,viewCount,hiddenSubscriberCount),' + | ||
'snippet(title,description,thumbnails,publishedAt,country,defaultLanguage),brandingSettings(image,channel(keywords,featuredChannelsUrls)),' + | ||
'status(isLinked,madeForKids,selfDeclaredMadeForKids))'; | ||
//# sourceMappingURL=channel.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.YTComment = void 0; | ||
class YTComment { | ||
constructor(youtube, data, type) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'comments'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,' + | ||
'snippet(authorDisplayName,authorProfileImageUrl,authorChannelId,authorChannelUrl,textDisplay,textOriginal,parentId,videoId,channelId,canRate,likeCount,publishedAt,updatedAt))'; | ||
/** | ||
* The YouTube object used to create the comment. | ||
*/ | ||
youtube; | ||
/** | ||
* The raw data from the YouTube API of the comment. | ||
*/ | ||
data; | ||
/** | ||
* The comment's unique YouTube ID. | ||
*/ | ||
id; | ||
/** | ||
* Whether or not this a full comment object. | ||
*/ | ||
full = true; | ||
/** | ||
* The comment's author. | ||
*/ | ||
author; | ||
/** | ||
* The comment's content. | ||
*/ | ||
text; | ||
/** | ||
* Whether or not you can like/dislike the comment. | ||
*/ | ||
rateable; | ||
/** | ||
* Either YouTube thinks it's popular, or it has at least 100 likes. | ||
*/ | ||
popular; | ||
/** | ||
* The number of likes the comment has received. | ||
*/ | ||
likes; | ||
/** | ||
* The url of the comment. | ||
*/ | ||
url; | ||
/** | ||
* The date the comment was published. | ||
*/ | ||
datePublished; | ||
/** | ||
* Either the date the comment was last edited, or the date it was | ||
* posted. | ||
*/ | ||
dateEdited; | ||
/** | ||
* The ID of the channel that uploaded the video this comment is on, if any. | ||
*/ | ||
channelId; | ||
/** | ||
* The ID of the video that this comment is on, if any. | ||
*/ | ||
videoId; | ||
/** | ||
* If this comment is a reply, then this is the ID of the comment it is replying to. | ||
*/ | ||
parentCommentId; | ||
/** | ||
* Replies directed to the comment. If the comment was fetched from a video, | ||
* then this will be partially filled. You'll need to use [[Comment.fetchReplies]] | ||
* to get all of the replies, though. | ||
*/ | ||
replies; | ||
constructor(youtube, data, full = true, replies) { | ||
this.youtube = youtube; | ||
this.data = data; | ||
this._init(data, type); | ||
if (replies) | ||
this.data.replies = replies; | ||
this._init(data, replies); | ||
} | ||
@@ -22,3 +95,3 @@ /** | ||
*/ | ||
_init(data, type) { | ||
_init(data, replies) { | ||
if (data.kind !== 'youtube#comment') { | ||
@@ -33,3 +106,3 @@ throw new Error(`Invalid comment type: ${data.kind}`); | ||
avatar: comment.snippet.authorProfileImageUrl, | ||
channelId: comment.snippet.authorChannelId.value, | ||
channelId: comment.snippet.authorChannelId?.value, | ||
channelUrl: comment.snippet.authorChannelUrl | ||
@@ -46,22 +119,24 @@ }; | ||
this.dateEdited = comment.snippet.updatedAt; | ||
this.parentId = comment.snippet.parentId ? comment.snippet.parentId : comment.snippet.videoId ? comment.snippet.videoId : comment.snippet.channelId; | ||
this.channelId = comment.snippet.channelId; | ||
this.videoId = comment.snippet.videoId; | ||
this.parentCommentId = comment.snippet.parentId; | ||
if (comment.snippet.videoId) { | ||
this.url = `https://youtube.com/watch?v=${comment.snippet.videoId}&lc=${comment.id}`; | ||
} | ||
} | ||
else { | ||
this.full = false; | ||
this.replies = []; | ||
if (replies) { | ||
for (const replyData of replies) { | ||
this.replies.push(new YTComment(this.youtube, replyData)); | ||
} | ||
} | ||
this.id = comment.id; | ||
if (this.parentId) { | ||
this.url = 'https://youtube.com/' + (type === 'channel' ? `channel/${this.parentId}/discussion?lc=${this.id}` : `watch?v=${this.parentId}&lc=${this.id}`); | ||
} | ||
this.replies = []; | ||
} | ||
/** | ||
* Fetches replies to the comment. | ||
* @param maxResults The maximum amount of replies to fetch. Fetches all comments if <=0. | ||
* @param pages The number of pages of comments to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchReplies(maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.replies = yield this.youtube.getCommentReplies(this.id, maxResults); | ||
return this.replies; | ||
}); | ||
async fetchReplies(pages, parts) { | ||
this.replies = await this.youtube.getCommentReplies(this.id, { pages }, parts); | ||
return this.replies; | ||
} | ||
@@ -75,6 +150,3 @@ /** | ||
edit(text) { | ||
if (this.data.snippet.parentId) { | ||
return this.youtube.oauth.editCommentReply(this.id, text); | ||
} | ||
return this.youtube.oauth.editComment(text, this.id); | ||
return this.youtube.oauth.editComment(this.id, text); | ||
} | ||
@@ -119,16 +191,3 @@ /** | ||
exports.YTComment = YTComment; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
YTComment.endpoint = 'comments'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
YTComment.part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
YTComment.fields = 'items(kind,id,' + | ||
'snippet(authorDisplayName,authorProfileImageUrl,authorChannelId,authorChannelUrl,textDisplay,textOriginal,parentId,videoId,channelId,canRate,likeCount,publishedAt,updatedAt))'; | ||
//# sourceMappingURL=comment.js.map |
"use strict"; | ||
/** | ||
* @packageDocumentation | ||
* @module Entities | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +14,0 @@ if (k2 === undefined) k2 = k; |
@@ -8,3 +8,39 @@ "use strict"; | ||
class Language { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'i18nLanguages'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,snippet(hl,name))'; | ||
/** | ||
* The YouTube object that created this language object. | ||
*/ | ||
youtube; | ||
/** | ||
* Whether or not this is a full language object. | ||
*/ | ||
full = true; | ||
/** | ||
* The raw data of this language. | ||
*/ | ||
data; | ||
/** | ||
* The ID of this language. | ||
*/ | ||
id; | ||
/** | ||
* The language code that uniquely identifies the language. | ||
*/ | ||
hl; | ||
/** | ||
* The language's name. | ||
*/ | ||
name; | ||
constructor(youtube, data, full = true) { | ||
this.youtube = youtube; | ||
@@ -23,3 +59,2 @@ this.data = data; | ||
this.id = language.id; | ||
this.full = true; | ||
/* istanbul ignore next */ | ||
@@ -30,22 +65,6 @@ if (language.snippet) { | ||
} | ||
else { | ||
/* istanbul ignore next */ | ||
this.full = false; | ||
} | ||
} | ||
} | ||
exports.Language = Language; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
Language.endpoint = 'i18nLanguages'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
Language.part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
Language.fields = 'items(kind,id,snippet(hl,name))'; | ||
//# sourceMappingURL=language.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -19,5 +10,74 @@ exports.Playlist = void 0; | ||
class Playlist { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'playlists'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet,contentDetails,player'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,snippet(tags,title,description,channelId,publishedAt,thumbnails),contentDetails(itemCount),player(embedHtml))'; | ||
/** | ||
* The YouTube object that created this playlist. | ||
*/ | ||
youtube; | ||
/** | ||
* The raw data of this playlist. | ||
*/ | ||
data; | ||
/** | ||
* Whether or not this is a full playlist object. | ||
*/ | ||
full; | ||
/** | ||
* The ID of this playlist. | ||
*/ | ||
id; | ||
/** | ||
* The title of the playlist. | ||
*/ | ||
title; | ||
/** | ||
* The description of the playlist. | ||
*/ | ||
description; | ||
/** | ||
* The videos in the playlist. Only available after calling [[Playlist.fetchVideos]]. | ||
*/ | ||
videos; | ||
/** | ||
* The ID of the creator of the playlist. | ||
*/ | ||
creatorId; | ||
/** | ||
* The url of the playlist. | ||
*/ | ||
url; | ||
/** | ||
* The date the playlist was created. | ||
*/ | ||
dateCreated; | ||
/** | ||
* The thumbnails for the playlist. | ||
*/ | ||
thumbnails; | ||
/** | ||
* The number of items in the playlist. | ||
*/ | ||
length; | ||
/** | ||
* An \<iframe\> tag that embeds a player that will play the playlist. | ||
*/ | ||
embedHtml; | ||
/** | ||
* The tags of the playlist. | ||
*/ | ||
tags; | ||
constructor(youtube, data, full = false) { | ||
this.youtube = youtube; | ||
this.data = data; | ||
this.full = full; | ||
this._init(data); | ||
@@ -29,4 +89,4 @@ } | ||
_init(data) { | ||
const playlist = data; | ||
if (data.kind === 'youtube#playlist') { | ||
const playlist = data; | ||
this.id = playlist.id; | ||
@@ -41,3 +101,2 @@ /* istanbul ignore next */ | ||
else if (data.kind === 'youtube#searchResult') { | ||
this.full = false; | ||
this.id = data.id.playlistId; | ||
@@ -49,13 +108,10 @@ } | ||
/* istanbul ignore next */ | ||
if (data.snippet) { | ||
this.tags = data.snippet.tags; | ||
this.title = data.snippet.title; | ||
this.description = data.snippet.description; | ||
this.creatorId = data.snippet.channelId; | ||
this.dateCreated = new Date(data.snippet.publishedAt); | ||
this.thumbnails = data.snippet.thumbnails; | ||
if (playlist.snippet) { | ||
this.tags = playlist.snippet.tags; | ||
this.title = playlist.snippet.title; | ||
this.description = playlist.snippet.description; | ||
this.creatorId = playlist.snippet.channelId; | ||
this.dateCreated = new Date(playlist.snippet.publishedAt); | ||
this.thumbnails = playlist.snippet.thumbnails; | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
this.url = `https://youtube.com/playlist?list=${this.id}`; | ||
@@ -65,9 +121,7 @@ } | ||
* Adds videos in this playlist to the `videos` property of this playlist. | ||
* @param maxResults Fetches all videos if <=0. | ||
* @param pages The number of pages of videos to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchVideos(maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.videos = yield this.youtube.getPlaylistItems(this.id, maxResults); | ||
return this.videos; | ||
}); | ||
async fetchVideos(pages, parts) { | ||
this.videos = await this.youtube.getPlaylistItems(this.id, { pages }, parts); | ||
return this.videos; | ||
} | ||
@@ -78,7 +132,5 @@ /** | ||
*/ | ||
fetch() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playlist = yield this.youtube.getPlaylist(this.id); | ||
return Object.assign(this, playlist); | ||
}); | ||
async fetch(parts) { | ||
const playlist = await this.youtube.getPlaylist(this.id, parts); | ||
return Object.assign(this, playlist); | ||
} | ||
@@ -98,7 +150,5 @@ /** | ||
/* istanbul ignore next */ | ||
update(title, description, privacy, tags, language, localizations) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const newPlaylist = yield this.youtube.oauth.updatePlaylist(this.id, title, description, privacy, tags, language, localizations); | ||
return Object.assign(this, Object.assign(Object.assign({}, newPlaylist), { full: true })); | ||
}); | ||
async update(title, description, privacy, tags, language, localizations) { | ||
const newPlaylist = await this.youtube.oauth.updatePlaylist(this.id, title, description, privacy, tags, language, localizations); | ||
return Object.assign(this, { ...newPlaylist, full: true }); | ||
} | ||
@@ -113,14 +163,12 @@ /** | ||
/* istanbul ignore next */ | ||
addVideo(videoResolvable, position, note) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, __1.Video); | ||
const video = yield this.youtube.oauth.addPlaylistItem(this.id, videoId, position, note); | ||
if (this.videos) { | ||
this.videos.push(video); | ||
} | ||
else { | ||
this.videos = [video]; | ||
} | ||
return video; | ||
}); | ||
async addVideo(videoResolvable, position, note) { | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, __1.Video); | ||
const video = await this.youtube.oauth.addPlaylistItem(this.id, videoId, position, note); | ||
if (this.videos) { | ||
this.videos.push(video); | ||
} | ||
else { | ||
this.videos = [video]; | ||
} | ||
return video; | ||
} | ||
@@ -136,8 +184,6 @@ /** | ||
/* istanbul ignore next */ | ||
updateVideo(videoResolvable, position, note, itemId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, __1.Video); | ||
const playlistItemId = itemId ? itemId : (yield services_1.GenericService.getPaginatedItems(this.youtube, 'playlistItems', false, this.id, 1, videoId))[0].id; | ||
return this.youtube.oauth.updatePlaylistItem(playlistItemId, this.id, videoId, position, note); | ||
}); | ||
async updateVideo(videoResolvable, position, note, itemId) { | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, __1.Video); | ||
const playlistItemId = itemId ?? (await services_1.GenericService.getPaginatedItems({ youtube: this.youtube, type: __1.PaginatedItemType.PlaylistItems, mine: false, id: this.id, maxPerPage: 1, subId: videoId }))[0].id; | ||
return this.youtube.oauth.updatePlaylistItem(playlistItemId, this.id, videoId, position, note); | ||
} | ||
@@ -147,20 +193,23 @@ /** | ||
* Must be using an access token with correct scopes. | ||
* @param videoResolvable The URL, ID, or Title of the video. Must specify this or `itemId`. | ||
* @param itemId The playlist item ID if you have it. Must specify this or `videoResolvable`. | ||
* @param videoResolvable The URL, ID, or Title of the video. | ||
*/ | ||
/* istanbul ignore next */ | ||
removeVideo(videoResolvable, itemId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!videoResolvable && !itemId) { | ||
return Promise.reject('Must specify either videoResolvable or itemId'); | ||
async removeVideo(videoResolvable) { | ||
const playlistItemId = (await services_1.GenericService.getPaginatedItems({ youtube: this.youtube, type: __1.PaginatedItemType.PlaylistItems, mine: false, id: this.id, maxPerPage: 1, subId: await services_1.GenericService.getId(this.youtube, videoResolvable, __1.Video) }))[0].id; | ||
return this.removeItem(playlistItemId); | ||
} | ||
/** | ||
* Removes a [[Video]] from the playlist. | ||
* Must be using an access token with correct scopes. | ||
* @param playlistItemId The playlist item ID (not the same as video id. See [[Playlist.removeVideo]]). | ||
*/ | ||
/* istanbul ignore next */ | ||
async removeItem(playlistItemId) { | ||
await this.youtube.oauth.deletePlaylistItem(playlistItemId); | ||
if (this.videos) { | ||
const index = this.videos.findIndex(v => v.data.id === playlistItemId); | ||
if (index >= 0) { | ||
this.videos.splice(index, 1); | ||
} | ||
const playlistItemId = itemId ? itemId : (yield services_1.GenericService.getPaginatedItems(this.youtube, 'playlistItems', false, this.id, 1, yield services_1.GenericService.getId(this.youtube, videoResolvable, __1.Video)))[0].id; | ||
yield this.youtube.oauth.deletePlaylistItem(playlistItemId); | ||
if (this.videos) { | ||
const index = this.videos.findIndex(v => v.data.id === playlistItemId); | ||
if (index) { | ||
this.videos.splice(index, 1); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
@@ -177,15 +226,3 @@ /** | ||
exports.Playlist = Playlist; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
Playlist.endpoint = 'playlists'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
Playlist.part = 'snippet,contentDetails,player'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
Playlist.fields = 'items(kind,id,snippet(tags,title,description,channelId,publishedAt,thumbnails),contentDetails(itemCount),player(embedHtml))'; | ||
//# sourceMappingURL=playlist.js.map |
@@ -8,3 +8,39 @@ "use strict"; | ||
class Region { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'i18nRegions'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,snippet(gl,name))'; | ||
/** | ||
* The YouTube object that created this region object. | ||
*/ | ||
youtube; | ||
/** | ||
* Whether or not this is a full region object. | ||
*/ | ||
full = true; | ||
/** | ||
* The raw data of this region. | ||
*/ | ||
data; | ||
/** | ||
* The ID of this region. | ||
*/ | ||
id; | ||
/** | ||
* The country code that uniquely identifies the region. | ||
*/ | ||
gl; | ||
/** | ||
* The region's name. | ||
*/ | ||
name; | ||
constructor(youtube, data, full = true) { | ||
this.youtube = youtube; | ||
@@ -23,3 +59,2 @@ this.data = data; | ||
this.id = region.id; | ||
this.full = true; | ||
/* istanbul ignore next */ | ||
@@ -30,22 +65,6 @@ if (region.snippet) { | ||
} | ||
else { | ||
/* istanbul ignore next */ | ||
this.full = false; | ||
} | ||
} | ||
} | ||
exports.Region = Region; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
Region.endpoint = 'i18nRegions'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
Region.part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
Region.fields = 'items(kind,id,snippet(gl,name))'; | ||
//# sourceMappingURL=region.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,3 +8,70 @@ exports.Subscription = void 0; | ||
class Subscription { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'subscriptions'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet,contentDetails,subscriberSnippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,snippet(publishedAt,title,channelTitle,description,resourceId(channelId),channelId,thumbnails),' + | ||
'contentDetails(newItemCount,totalItemCount,activityType),subscriberSnippet(title,description,thumbnails))'; | ||
/** | ||
* The YouTube object that created this subscription object. | ||
*/ | ||
youtube; | ||
/** | ||
* Whether or not this is a full subscription object. | ||
*/ | ||
full = true; | ||
/** | ||
* The raw data of this subscription. | ||
*/ | ||
data; | ||
/** | ||
* The ID of this subscription. | ||
*/ | ||
id; | ||
/** | ||
* The date that the user subscribed to the channel on. | ||
*/ | ||
dateSubscribed; | ||
/** | ||
* Information on the [[Channel]] that the user subscribed to. | ||
*/ | ||
channel; | ||
/** | ||
* The title of the subscription. | ||
*/ | ||
title; | ||
/** | ||
* The details of the subscription. | ||
*/ | ||
description; | ||
/** | ||
* Information on the user that subscribed to the channel. | ||
* **CURRENTLY NOT WORKING**, see https://issuetracker.google.com/issues/181152600 | ||
*/ | ||
/* istanbul ignore next */ | ||
subscriber; | ||
/** | ||
* Thumbnail images for the subscription. | ||
*/ | ||
thumbnails; | ||
/** | ||
* Statistics on the items that the subscription points to. | ||
* **CURRENTLY NOT WORKING**, see https://issuetracker.google.com/issues/181152600 | ||
*/ | ||
/* istanbul ignore next */ | ||
items; | ||
/** | ||
* The activities that the user has subscribed to. | ||
* **CURRENTLY NOT WORKING**, see https://issuetracker.google.com/issues/181152600 | ||
*/ | ||
/* istanbul ignore next */ | ||
activities; | ||
constructor(youtube, data, full = true) { | ||
this.youtube = youtube; | ||
@@ -32,3 +90,2 @@ this.data = data; | ||
this.id = subscription.id; | ||
this.full = true; | ||
/* istanbul ignore next */ | ||
@@ -51,6 +108,2 @@ if (subscription.snippet) { | ||
} | ||
else { | ||
/* istanbul ignore next */ | ||
this.full = false; | ||
} | ||
/* **CURRENTLY NOT WORKING**, see https://issuetracker.google.com/issues/181152600 */ | ||
@@ -65,5 +118,2 @@ /* istanbul ignore next */ | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
/* **CURRENTLY NOT WORKING**, see https://issuetracker.google.com/issues/181152600 */ | ||
@@ -76,5 +126,2 @@ /* istanbul ignore next */ | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
} | ||
@@ -86,28 +133,13 @@ /** | ||
*/ | ||
fetch() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let subscription = yield this.youtube.getSubscription(this.id).catch((e) => e); | ||
/* istanbul ignore next */ | ||
if (typeof subscription === 'string') { | ||
subscription = yield this.youtube.getSubscriptionByChannels(this.subscriber.id, this.channel.id).catch(e => e); | ||
} | ||
return Object.assign(this, subscription); | ||
}); | ||
async fetch(parts) { | ||
let subscription = await this.youtube.getSubscription(this.id, parts).catch((e) => e); | ||
/* istanbul ignore next */ | ||
if (typeof subscription === 'string') { | ||
subscription = await this.youtube.getSubscriptionByChannels(this.subscriber.id, this.channel.id); | ||
} | ||
return Object.assign(this, subscription); | ||
} | ||
} | ||
exports.Subscription = Subscription; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
Subscription.endpoint = 'subscriptions'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
Subscription.part = 'snippet,contentDetails,subscriberSnippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
Subscription.fields = 'items(kind,id,snippet(publishedAt,title,channelTitle,description,resourceId(channelId),channelId,thumbnails),' + | ||
'contentDetails(newItemCount,totalItemCount,activityType),subscriberSnippet(title,description,thumbnails))'; | ||
//# sourceMappingURL=subscription.js.map |
@@ -10,3 +10,39 @@ "use strict"; | ||
class VideoAbuseReportReason { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'videoAbuseReportReasons'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'id,snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,snippet(label,secondaryReasons))'; | ||
/** | ||
* The YouTube object that created this reason object. | ||
*/ | ||
youtube; | ||
/** | ||
* Whether or not this is a full reason object. | ||
*/ | ||
full = true; | ||
/** | ||
* The raw data of this reason. | ||
*/ | ||
data; | ||
/** | ||
* The ID of this reason. | ||
*/ | ||
id; | ||
/** | ||
* The label text of this reason. | ||
*/ | ||
label; | ||
/** | ||
* A list of secondary reasons associated with the reason, if any are available. | ||
*/ | ||
secondaryReasons; | ||
constructor(youtube, data, full = true) { | ||
this.youtube = youtube; | ||
@@ -25,3 +61,2 @@ this.data = data; | ||
this.id = reason.id; | ||
this.full = true; | ||
/* istanbul ignore next */ | ||
@@ -32,22 +67,6 @@ if (reason.snippet) { | ||
} | ||
else { | ||
/* istanbul ignore next */ | ||
this.full = false; | ||
} | ||
} | ||
} | ||
exports.VideoAbuseReportReason = VideoAbuseReportReason; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
VideoAbuseReportReason.endpoint = 'videoAbuseReportReasons'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
VideoAbuseReportReason.part = 'id,snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
VideoAbuseReportReason.fields = 'items(kind,id,snippet(label,secondaryReasons))'; | ||
//# sourceMappingURL=video-abuse-report-reason.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,3 +8,43 @@ exports.VideoCategory = void 0; | ||
class VideoCategory { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'videoCategories'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,snippet(channelId,title,assignable))'; | ||
/** | ||
* The YouTube object that created this category object. | ||
*/ | ||
youtube; | ||
/** | ||
* Whether or not this is a full category object. | ||
*/ | ||
full = true; | ||
/** | ||
* The raw data of this category. | ||
*/ | ||
data; | ||
/** | ||
* The ID of this category. | ||
*/ | ||
id; | ||
/** | ||
* The [[Channel]] that created the category. | ||
*/ | ||
channelId; | ||
/** | ||
* The category's title. | ||
*/ | ||
title; | ||
/** | ||
* Whether or not videos can be associated with the category. | ||
*/ | ||
assignable; | ||
constructor(youtube, data, full = true) { | ||
this.youtube = youtube; | ||
@@ -32,3 +63,2 @@ this.data = data; | ||
this.id = category.id; | ||
this.full = true; | ||
/* istanbul ignore next */ | ||
@@ -40,6 +70,2 @@ if (category.snippet) { | ||
} | ||
else { | ||
/* istanbul ignore next */ | ||
this.full = false; | ||
} | ||
} | ||
@@ -50,7 +76,5 @@ /** | ||
*/ | ||
fetch() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const category = yield this.youtube.getCategory(this.id); | ||
return Object.assign(this, category); | ||
}); | ||
async fetch() { | ||
const category = await this.youtube.getCategory(this.id); | ||
return Object.assign(this, category); | ||
} | ||
@@ -65,15 +89,3 @@ /** | ||
exports.VideoCategory = VideoCategory; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
VideoCategory.endpoint = 'videoCategories'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
VideoCategory.part = 'snippet'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
VideoCategory.fields = 'items(kind,id,snippet(channelId,title,assignable))'; | ||
//# sourceMappingURL=video-category.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -18,5 +9,126 @@ exports.Video = void 0; | ||
class Video { | ||
constructor(youtube, data) { | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
static endpoint = 'videos'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
static part = 'snippet,contentDetails,statistics,status'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
static fields = 'items(kind,id,contentDetails(duration),statistics(likeCount,dislikeCount,viewCount,commentCount),' + | ||
'status(privacyStatus,madeForKids,selfDeclaredMadeForKids),snippet(title,description,thumbnails,tags,publishedAt,channelId,channelTitle,liveBroadcastContent,' + | ||
'categoryId))'; | ||
/** | ||
* YouTube object that created the video. | ||
*/ | ||
youtube; | ||
/** | ||
* The raw data of the video. | ||
*/ | ||
data; | ||
/** | ||
* Whether or not this is a full video object (would it be the same if we ran [[Video.fetch]] under the same conditions as last time?). | ||
*/ | ||
full; | ||
/** | ||
* The ID of the video. | ||
*/ | ||
id; | ||
/** | ||
* The title of the video. | ||
*/ | ||
title; | ||
/** | ||
* The description of the video. | ||
*/ | ||
description; | ||
/** | ||
* The thumbnails of the video. | ||
*/ | ||
thumbnails; | ||
/** | ||
* The tags of the video. | ||
*/ | ||
tags; | ||
/** | ||
* The date the video was published. | ||
*/ | ||
datePublished; | ||
/** | ||
* Information on the channel that uploaded the video. | ||
*/ | ||
channel; | ||
/** | ||
* @ignore | ||
*/ | ||
_length; | ||
/** | ||
* The minutes of the video. | ||
*/ | ||
minutes; | ||
/** | ||
* The seconds of the video. | ||
*/ | ||
seconds; | ||
/** | ||
* The url of the video. | ||
*/ | ||
url; | ||
/** | ||
* The short url of the video, i.e. https://youtu.be/id | ||
*/ | ||
shortUrl; | ||
/** | ||
* The number of likes the video has. | ||
*/ | ||
likes; | ||
/** | ||
* The number of dislikes the video has. | ||
*/ | ||
dislikes; | ||
/** | ||
* The number of views the video has. | ||
*/ | ||
views; | ||
/** | ||
* Whether or not this video COULD BE private. True if the video might | ||
* be private, as you cannot check if playlist items are private. | ||
* | ||
* I would recommend that you try and fetch the video and catch an error | ||
* if it is from a playlist & marked as private. | ||
*/ | ||
private; | ||
/** | ||
* The video's comments. Only defined when [[Video.fetchComments]] is called. | ||
*/ | ||
comments; | ||
/** | ||
* The number of comments on the video. | ||
*/ | ||
commentCount; | ||
/** | ||
* If this is a ongoing livestream, this is `live`. | ||
* If this is an upcoming livestream, this is `upcoming`. | ||
* If this is not a livestream, this is `false`. | ||
*/ | ||
liveStatus; | ||
/** | ||
* The video category associated with the video. | ||
*/ | ||
category; | ||
/** | ||
* Properties to do with videos made for children. | ||
*/ | ||
kids; | ||
/** | ||
* The caption data associated with this video. Only available after running [[Video.fetchCaptions]]. | ||
*/ | ||
captions; | ||
constructor(youtube, data, full = false) { | ||
this.youtube = youtube; | ||
this.data = data; | ||
this.full = full; | ||
this._init(data); | ||
@@ -36,5 +148,2 @@ } | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
/* istanbul ignore next */ | ||
@@ -47,9 +156,5 @@ if (video.statistics) { | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
this.id = video.id; | ||
} | ||
else if (data.kind === 'youtube#playlistItem') { | ||
this.full = false; | ||
this.id = data.snippet.resourceId.videoId; | ||
@@ -59,3 +164,2 @@ this.private = data.snippet.title === 'Private video'; | ||
else if (data.kind === 'youtube#searchResult') { | ||
this.full = false; | ||
this.id = data.id.videoId; | ||
@@ -82,5 +186,2 @@ } | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
/* istanbul ignore next */ | ||
@@ -94,5 +195,2 @@ if (data.status) { | ||
} | ||
else { | ||
this.full = false; | ||
} | ||
this.url = `https://youtube.com/watch?v=${this.id}`; | ||
@@ -108,13 +206,11 @@ this.shortUrl = `https://youtu.be/${this.id}`; | ||
/* istanbul ignore next */ | ||
postComment(text) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const comment = yield this.youtube.oauth.postComment(text, this.channel.id, this.id); | ||
if (this.comments !== undefined) { | ||
this.comments.push(comment); | ||
} | ||
else { | ||
this.comments = [comment]; | ||
} | ||
return comment; | ||
}); | ||
async postComment(text) { | ||
const comment = await this.youtube.oauth.postComment(text, this.channel.id, this.id); | ||
if (this.comments !== undefined) { | ||
this.comments.push(comment); | ||
} | ||
else { | ||
this.comments = [comment]; | ||
} | ||
return comment; | ||
} | ||
@@ -125,27 +221,22 @@ /** | ||
*/ | ||
fetch() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const video = yield this.youtube.getVideo(this.id); | ||
return Object.assign(this, video); | ||
}); | ||
async fetch(parts) { | ||
const video = await this.youtube.getVideo(this.id, parts); | ||
return Object.assign(this, video); | ||
} | ||
/** | ||
* Fetches the video's comments and assigns them to Video#comments. | ||
* @param maxResults The maximum amount of comments to fetch | ||
* Fetches the video's comments and assigns them to [[Video.comments]]. | ||
* @param pages The number of pages of comments to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchComments(maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.comments = yield this.youtube.getVideoComments(this.id, maxResults); | ||
return this.comments; | ||
}); | ||
async fetchComments(pages, parts) { | ||
this.comments = await this.youtube.getVideoComments(this.id, { pages }, parts); | ||
return this.comments; | ||
} | ||
/** | ||
* Gets the user's rating on the video. | ||
* Must be using an access token with correct scopes. | ||
*/ | ||
/* istanbul ignore next */ | ||
getRating() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.youtube.oauth.getMyRatings([this.id]); | ||
return response[0].rating; | ||
}); | ||
async getRating() { | ||
const response = await this.youtube.oauth.getMyRatings([this.id]); | ||
return response[0].rating; | ||
} | ||
@@ -204,7 +295,5 @@ /** | ||
/* istanbul ignore next */ | ||
update(video) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const newVideo = yield this.youtube.oauth.updateVideo(video); | ||
return Object.assign(this, Object.assign(Object.assign({}, newVideo), { full: true })); | ||
}); | ||
async update(video) { | ||
const newVideo = await this.youtube.oauth.updateVideo(video); | ||
return Object.assign(this, { ...newVideo, full: true }); | ||
} | ||
@@ -217,7 +306,5 @@ /** | ||
/* istanbul ignore next */ | ||
setThumbnail(image) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const newThumbnails = yield this.youtube.oauth.setThumbnail(this.id, image); | ||
return Object.assign(this.thumbnails, newThumbnails); | ||
}); | ||
async setThumbnail(image) { | ||
const newThumbnails = await this.youtube.oauth.setThumbnail(this.id, image); | ||
return Object.assign(this.thumbnails, newThumbnails); | ||
} | ||
@@ -229,7 +316,5 @@ /** | ||
/* istanbul ignore next */ | ||
fetchCaptions() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.captions = yield this.youtube.oauth.getCaptions(this.id); | ||
return this.captions; | ||
}); | ||
async fetchCaptions() { | ||
this.captions = await this.youtube.oauth.getCaptions(this.id); | ||
return this.captions; | ||
} | ||
@@ -245,7 +330,5 @@ /** | ||
/* istanbul ignore next */ | ||
uploadCaption(language, name, track, draft = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const toReturn = yield this.youtube.oauth.uploadCaption(this.id, language, name, track, draft); | ||
return toReturn; | ||
}); | ||
async uploadCaption(language, name, track, draft = false) { | ||
const toReturn = await this.youtube.oauth.uploadCaption(this.id, language, name, track, draft); | ||
return toReturn; | ||
} | ||
@@ -259,25 +342,9 @@ /** | ||
/* istanbul ignore next */ | ||
updateCaption(track, draft = null) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const toReturn = yield this.youtube.oauth.updateCaption(this.id, track, draft); | ||
return toReturn; | ||
}); | ||
async updateCaption(track, draft = null) { | ||
const toReturn = await this.youtube.oauth.updateCaption(this.id, track, draft); | ||
return toReturn; | ||
} | ||
} | ||
exports.Video = Video; | ||
/** | ||
* The name of the endpoint used for this entity. | ||
*/ | ||
Video.endpoint = 'videos'; | ||
/** | ||
* The parts to request for this entity. | ||
*/ | ||
Video.part = 'snippet,contentDetails,statistics,status'; | ||
/** | ||
* The fields to request for this entity. | ||
*/ | ||
Video.fields = 'items(kind,id,contentDetails(duration),statistics(likeCount,dislikeCount,viewCount,commentCount),' + | ||
'status(privacyStatus,madeForKids,selfDeclaredMadeForKids),snippet(title,description,thumbnails,tags,publishedAt,channelId,channelTitle,liveBroadcastContent,' + | ||
'categoryId))'; | ||
//# sourceMappingURL=video.js.map |
240
out/index.js
"use strict"; | ||
/** | ||
* @module Library Exports | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -12,11 +19,2 @@ if (k2 === undefined) k2 = k; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -28,2 +26,3 @@ exports.YouTube = void 0; | ||
const services_1 = require("./services"); | ||
const types_1 = require("./types"); | ||
__exportStar(require("./entities"), exports); | ||
@@ -36,19 +35,45 @@ __exportStar(require("./types"), exports); | ||
/** | ||
* @ignore | ||
*/ | ||
_shouldCache; | ||
/** | ||
* @ignore | ||
*/ | ||
_cacheSearches; | ||
/** | ||
* @ignore | ||
*/ | ||
_cacheTTL; | ||
/** | ||
* @ignore | ||
*/ | ||
_request = new util_1.Request('https://www.googleapis.com/youtube/v3'); | ||
/** | ||
* @ignore | ||
*/ | ||
_upload = new util_1.Request('https://www.googleapis.com/upload/youtube/v3'); | ||
token; | ||
accessToken; | ||
/** | ||
* Methods requiring an OAuth token. | ||
*/ | ||
oauth; | ||
/** | ||
* The language for the API to respond in. See [[YouTube.getLanguages]]. | ||
*/ | ||
language; | ||
/** | ||
* The region for the API cater responses to. See [[YouTube.getRegions]]. | ||
*/ | ||
region; | ||
/** | ||
* | ||
* @param token Your YouTube Data API v3 token. Don't share this with anybody. | ||
* It could be an API key or an OAuth 2.0 token. | ||
* @param accessToken A Google OAuth 2.0 access token. Used for [[YouTube#oauth]] methods. | ||
* @param accessToken A Google OAuth 2.0 access token. Used for [[YouTube.oauth]] methods. | ||
* @param options Caching options. Recommended to change. | ||
* @param language The language for the API to respond in. See [[YouTube#getLanguages]]. | ||
* @param region The region for the API cater responses to. See [[YouTube#getRegions]]. | ||
* @param language The language for the API to respond in. See [[YouTube.getLanguages]]. | ||
* @param region The region for the API cater responses to. See [[YouTube.getRegions]]. | ||
*/ | ||
constructor(token, accessToken, options = { cache: true, cacheTTL: 600, cacheCheckInterval: 600, cacheSearches: true }, language = 'en_US', region = 'US') { | ||
/** | ||
* @ignore | ||
*/ | ||
this._request = new util_1.Request('https://www.googleapis.com/youtube/v3'); | ||
/** | ||
* @ignore | ||
*/ | ||
this._upload = new util_1.Request('https://www.googleapis.com/upload/youtube/v3'); | ||
this.token = token; | ||
@@ -82,3 +107,3 @@ this.accessToken = accessToken; | ||
* @param searchTerm What to search for on YouTube. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. Max 50. | ||
* @param fields The fields to include in the response. Includes all by default. | ||
@@ -93,3 +118,3 @@ * @param pageToken The page token to start at. Provide this if you have received it as output from a call to a search method. | ||
* @param searchTerm What to search for on YouTube. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. Max 50. | ||
* @param pageToken The page token to start at. Provide this if you have received it as output from a call to a search method. | ||
@@ -107,3 +132,3 @@ * @param channelId The channel ID that you want to specifically search for. | ||
* @param searchTerm What to search for on YouTube. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. Max 50. | ||
* @param pageToken The page token to start at. Provide this if you have received it as output from a call to a search method. | ||
@@ -117,3 +142,3 @@ */ | ||
* @param searchTerm What to search for on YouTube. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. Max 50. | ||
* @param pageToken The page token to start at. Provide this if you have received it as output from a call to a search method. | ||
@@ -128,8 +153,7 @@ */ | ||
* @param videoResolvable The URL, ID, or Title of the video. | ||
* @param parts The parts of the video to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getVideo(videoResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const id = yield services_1.GenericService.getId(this, videoResolvable, entities_1.Video); | ||
return services_1.GenericService.getItem(this, entities_1.Video, false, id); | ||
}); | ||
async getVideo(videoResolvable, parts) { | ||
const id = await services_1.GenericService.getId(this, videoResolvable, entities_1.Video); | ||
return services_1.GenericService.getItem(this, entities_1.Video, false, id, parts); | ||
} | ||
@@ -141,8 +165,7 @@ /** | ||
* @param channelResolvable The Username, URL or ID of the channel. | ||
* @param parts The parts of the channel to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getChannel(channelResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const id = yield services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return services_1.GenericService.getItem(this, entities_1.Channel, false, id); | ||
}); | ||
async getChannel(channelResolvable, parts) { | ||
const id = await services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return services_1.GenericService.getItem(this, entities_1.Channel, false, id, parts); | ||
} | ||
@@ -153,8 +176,7 @@ /** | ||
* @param playlistResolvable The URL, ID, or Title of the playlist. | ||
* @param parts The parts of the playlist to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getPlaylist(playlistResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const id = yield services_1.GenericService.getId(this, playlistResolvable, entities_1.Playlist); | ||
return services_1.GenericService.getItem(this, entities_1.Playlist, false, id); | ||
}); | ||
async getPlaylist(playlistResolvable, parts) { | ||
const id = await services_1.GenericService.getId(this, playlistResolvable, entities_1.Playlist); | ||
return services_1.GenericService.getItem(this, entities_1.Playlist, false, id, parts); | ||
} | ||
@@ -164,5 +186,6 @@ /** | ||
* @param commentId The ID of the comment. | ||
* @param parts The parts of the comment to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getComment(commentId) { | ||
return services_1.GenericService.getItem(this, entities_1.YTComment, false, commentId); | ||
getComment(commentId, parts) { | ||
return services_1.GenericService.getItem(this, entities_1.YTComment, false, commentId, parts); | ||
} | ||
@@ -172,5 +195,6 @@ /** | ||
* @param subscriptionId The ID of the subscription. | ||
* @param parts The parts of the subscription to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getSubscription(subscriptionId) { | ||
return services_1.GenericService.getItem(this, entities_1.Subscription, false, subscriptionId); | ||
getSubscription(subscriptionId, parts) { | ||
return services_1.GenericService.getItem(this, entities_1.Subscription, false, subscriptionId, parts); | ||
} | ||
@@ -187,5 +211,6 @@ /** | ||
* @param categoryId The ID of the section. | ||
* @param parts The parts of the channel section to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getChannelSection(sectionId) { | ||
return services_1.GenericService.getItem(this, entities_1.ChannelSection, false, sectionId); | ||
getChannelSection(sectionId, parts) { | ||
return services_1.GenericService.getItem(this, entities_1.ChannelSection, false, sectionId, parts); | ||
} | ||
@@ -196,96 +221,103 @@ /** | ||
* @param channelResolvable A resolvable channel that is the channel being subscribed to. | ||
* @param parts The parts of the subscription to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getSubscriptionByChannels(subscriberResolvable, channelResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const subscriberId = yield services_1.GenericService.getId(this, subscriberResolvable, entities_1.Channel); | ||
const channelId = yield services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return services_1.SubscriptionService.getSubscriptionByChannels(this, subscriberId, channelId); | ||
}); | ||
async getSubscriptionByChannels(subscriberResolvable, channelResolvable, parts) { | ||
const subscriberId = await services_1.GenericService.getId(this, subscriberResolvable, entities_1.Channel); | ||
const channelId = await services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return services_1.SubscriptionService.getSubscriptionByChannels(this, subscriberId, channelId, parts); | ||
} | ||
/** | ||
* Get `maxResults` videos in a [[Playlist]]. Used mostly internally with `Playlist#fetchVideos`. | ||
* Get `maxPerPage * pages` videos in a [[Playlist]]. Used mostly internally with [[Playlist.fetchVideos]]. | ||
* @param playlistResolvable The URL, ID, or Title of the playlist. | ||
* @param maxResults The maximum amount of videos to get from the playlist. If <=0, returns all videos in the playlist. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the videos to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial video objects. | ||
*/ | ||
getPlaylistItems(playlistResolvable, maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playlistId = yield services_1.GenericService.getId(this, playlistResolvable, entities_1.Playlist); | ||
return services_1.GenericService.getPaginatedItems(this, 'playlistItems', false, playlistId, maxResults); | ||
}); | ||
async getPlaylistItems(playlistResolvable, pageOptions, parts) { | ||
const playlistId = await services_1.GenericService.getId(this, playlistResolvable, entities_1.Playlist); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.PlaylistItems, id: playlistId, ...pageOptions, parts })).results; | ||
} | ||
/** | ||
* Get `maxResults` [[YTComment]]s from a [[Video]]. Used mostly internally with `Video#fetchComments`. | ||
* Get `maxPerPage * pages` [[YTComment]]s from a [[Video]]. Used mostly internally with [[Video.fetchComments]]. | ||
* @param videoResolvable The URL, ID, or Title of the video. | ||
* @param maxResults The maximum amount of comments to get from the video. If <=0, returns all comments on the video. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the comments to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial comment objects. | ||
*/ | ||
getVideoComments(videoResolvable, maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const videoId = yield services_1.GenericService.getId(this, videoResolvable, entities_1.Video); | ||
return services_1.GenericService.getPaginatedItems(this, 'commentThreads:video', false, videoId, maxResults); | ||
}); | ||
async getVideoComments(videoResolvable, pageOptions, parts) { | ||
const videoId = await services_1.GenericService.getId(this, videoResolvable, entities_1.Video); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.VideoComments, id: videoId, ...pageOptions, parts })).results; | ||
} | ||
/** | ||
* Get `maxResults` [[YTComment]]s from a [[Channel]]'s discussion tab. Used mostly internally with `Channel#fetchComments`. | ||
* @deprecated See https://support.google.com/youtube/thread/130882091?hl=en&msgid=131295194 | ||
* | ||
* Get `maxPerPage * pages` [[YTComment]]s from a [[Channel]]'s discussion tab. Used mostly internally with [[Channel.fetchComments]]. | ||
* @param channelResolvable The Username, URL, or ID of the channel. | ||
* @param maxResults The maximum amount of comments to get from the channel. If <=0, returns all comments on the channel. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the comments to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial comment objects. | ||
*/ | ||
getChannelComments(channelResolvable, maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const channelId = yield services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return services_1.GenericService.getPaginatedItems(this, 'commentThreads:channel', false, channelId, maxResults); | ||
}); | ||
async getChannelComments(channelResolvable, pageOptions, parts) { | ||
const channelId = await services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.ChannelComments, id: channelId, ...pageOptions, parts })).results; | ||
} | ||
/** | ||
* Get `maxResults` of a [[Channel]]'s [[Playlist]]s. Used mostly internally with `Channel#fetchPlaylists`. | ||
* Get `maxPerPage * pages` of a [[Channel]]'s [[Playlist]]s. Used mostly internally with [[Channel.fetchPlaylists]]. | ||
* @param channelResolvable The Username, URL, or ID of the channel. | ||
* @param maxResults The maximum amount of playlists to get from the channel. If <=0, returns all playlists. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the playlists to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial playlist objects. | ||
*/ | ||
getChannelPlaylists(channelResolvable, maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const channelId = yield services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return services_1.GenericService.getPaginatedItems(this, 'playlists:channel', false, channelId, maxResults); | ||
}); | ||
async getChannelPlaylists(channelResolvable, pageOptions, parts) { | ||
const channelId = await services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.Playlists, id: channelId, ...pageOptions, parts })).results; | ||
} | ||
/** | ||
* Get `maxResults` of a [[Channel]]'s [[Subscription]]s. Used mostly internally with `Channel#fetchSubscriptions`. | ||
* Get `maxPerPage * pages` of a [[Channel]]'s [[Subscription]]s. Used mostly internally with [[Channel.fetchSubscriptions]]. | ||
* @param channelResolvable The Username, URL, or ID of the channel. | ||
* @param maxResults The maximum amount of subscriptions to get from the channel. If <=0, returns all subscriptions. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the subscriptions to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial subscription objects. | ||
*/ | ||
getChannelSubscriptions(channelResolvable, maxResults = 10) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const channelId = yield services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return services_1.GenericService.getPaginatedItems(this, 'subscriptions', false, channelId, maxResults); | ||
}); | ||
async getChannelSubscriptions(channelResolvable, pageOptions, parts) { | ||
const channelId = await services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.Subscriptions, id: channelId, ...pageOptions, parts })).results; | ||
} | ||
/** | ||
* Get `maxResults` replies to a [[YTComment]]. Used mostly internally with `Comment#fetchReplies`. | ||
* Get `maxPerPage * pages` replies to a [[YTComment]]. Used mostly internally with [[Comment.fetchReplies]]. | ||
* @param commentId The ID of the comment to get replies from. | ||
* @param maxResults The maximum amount of replies to get. Gets all replies if <=0. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the replies to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial comment objects. | ||
*/ | ||
getCommentReplies(commentId, maxResults = 10) { | ||
return services_1.GenericService.getPaginatedItems(this, 'comments', false, commentId, maxResults); | ||
async getCommentReplies(commentId, pageOptions, parts) { | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.CommentReplies, id: commentId, ...pageOptions, parts })).results; | ||
} | ||
/** | ||
* Gets the [[ChannelSection]]s of a [[Channel]]. Used mostly internally with [[Channel#fetchSections]]. | ||
* Gets the [[ChannelSection]]s of a [[Channel]]. Used mostly internally with [[Channel.fetchSections]]. | ||
* @param channelResolvable The Username, URL, or ID of the channel to get the sections from. | ||
* @param parts The parts of the channel sections to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial channel section objects. | ||
*/ | ||
getChannelSections(channelResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const channelId = yield services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return services_1.GenericService.getPaginatedItems(this, 'channelSections', false, channelId); | ||
}); | ||
async getChannelSections(channelResolvable, parts) { | ||
const channelId = await services_1.GenericService.getId(this, channelResolvable, entities_1.Channel); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.ChannelSections, id: channelId, parts })).results; | ||
} | ||
/** | ||
* Get the list of categories in `this.region`. | ||
* @param all Whether or not to get all categories (otherwise just gets a page). | ||
*/ | ||
getCategories(all = false) { | ||
return services_1.GenericService.getPaginatedItems(this, 'videoCategories', false, null, all ? -1 : 100); | ||
async getCategories() { | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.VideoCategories })).results; | ||
} | ||
@@ -295,4 +327,4 @@ /** | ||
*/ | ||
getLanguages() { | ||
return services_1.GenericService.getPaginatedItems(this, 'i18nLanguages', false, null); | ||
async getLanguages() { | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.Languages })).results; | ||
} | ||
@@ -302,4 +334,4 @@ /** | ||
*/ | ||
getRegions() { | ||
return services_1.GenericService.getPaginatedItems(this, 'i18nRegions', false, null); | ||
async getRegions() { | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this, type: types_1.PaginatedItemType.Regions })).results; | ||
} | ||
@@ -306,0 +338,0 @@ } |
763
out/oauth.js
"use strict"; | ||
/* istanbul ignore file */ | ||
/* We ignore this file because OAuth endpoints are too taxing to test, they are instead manually tested. */ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OAuth = void 0; | ||
/** | ||
* @module OAuth | ||
*/ | ||
const _1 = require("."); | ||
@@ -21,5 +15,6 @@ const constants_1 = require("./constants"); | ||
* All methods requiring an OAuth access token. | ||
* Use `YouTube#oauth` to access these methods. | ||
* Use `YouTube.oauth` to access these methods. | ||
*/ | ||
class OAuth { | ||
youtube; | ||
/** | ||
@@ -44,5 +39,5 @@ * | ||
*/ | ||
getMe() { | ||
getMe(parts) { | ||
this.checkTokenAndThrow(); | ||
return services_1.GenericService.getItem(this.youtube, _1.Channel, true); | ||
return services_1.GenericService.getItem(this.youtube, _1.Channel, true, null, parts); | ||
} | ||
@@ -52,8 +47,9 @@ /** | ||
* Last tested 05/18/2020 11:48. PASSING | ||
* @param maxResults The maximum number of subscriptions to fetch. | ||
* Fetches 10 by default. Set to a value <=0 to fetch all. | ||
* @param maxPerPage The maximum number of subscriptions to fetch per page. | ||
* Fetches the maximum allowed by the API by default. | ||
* Set to a value <=0 to fetch all. | ||
*/ | ||
getMySubscriptions(maxResults = 10) { | ||
async getMySubscriptions(maxPerPage, parts) { | ||
this.checkTokenAndThrow(); | ||
return services_1.GenericService.getPaginatedItems(this.youtube, 'subscriptions', true, null, maxResults); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this.youtube, type: _1.PaginatedItemType.Subscriptions, mine: true, maxPerPage, parts })).results; | ||
} | ||
@@ -63,8 +59,9 @@ /** | ||
* Last tested 05/18/2020 11:48. PASSING | ||
* @param maxResults The maximum number of playlists to fetch. | ||
* Fetches 10 by default. Set to a value <=0 to fetch all. | ||
* @param maxPerPage The maximum number of playlists to fetch per page. | ||
* Fetches the maximum allowed by the API by default. | ||
* Set to a value <=0 to fetch all. | ||
*/ | ||
getMyPlaylists(maxResults = 10) { | ||
async getMyPlaylists(maxPerPage, parts) { | ||
this.checkTokenAndThrow(); | ||
return services_1.GenericService.getPaginatedItems(this.youtube, 'playlists:channel', true, null, maxResults); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this.youtube, type: _1.PaginatedItemType.Playlists, mine: true, maxPerPage, parts })).results; | ||
} | ||
@@ -79,17 +76,14 @@ /** | ||
*/ | ||
postComment(text, channelResolvable, videoResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const channelId = yield services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = JSON.parse(JSON.stringify(constants_1.COMMENT_THREAD_DATA)); | ||
data.snippet.topLevelComment.snippet.textOriginal = text; | ||
data.snippet.channelId = channelId; | ||
if (videoId) { | ||
data.snippet.videoId = videoId; | ||
} | ||
const result = yield this.youtube._request.post('commentThreads', { part: 'snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
const type = result.snippet.channelId ? 'channel' : 'video'; | ||
return new _1.YTComment(this.youtube, result.snippet.topLevelComment, type); | ||
}); | ||
async postComment(text, channelResolvable, videoResolvable) { | ||
this.checkTokenAndThrow(); | ||
const channelId = await services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = JSON.parse(JSON.stringify(constants_1.COMMENT_THREAD_DATA)); | ||
data.snippet.topLevelComment.snippet.textOriginal = text; | ||
data.snippet.channelId = channelId; | ||
if (videoId) { | ||
data.snippet.videoId = videoId; | ||
} | ||
const result = await this.youtube._request.post('commentThreads', { part: 'snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.YTComment(this.youtube, result.snippet.topLevelComment, true); | ||
} | ||
@@ -101,57 +95,34 @@ /** | ||
* @param text The text to reply with. | ||
* @param commentType What this comment is on - defaults to video. | ||
* Required for [[YTComment#url]] to be correct. | ||
* Required for [[YTComment.url]] to be correct. | ||
*/ | ||
replyToComment(commentId, text) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.COMMENT_DATA)); | ||
data.snippet = { parentId: commentId, textOriginal: text }; | ||
const response = yield this.youtube._request.post('comments', { part: 'id,snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.YTComment(this.youtube, response, response.snippet.channelId ? 'channel' : 'video'); | ||
}); | ||
async replyToComment(commentId, text) { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.COMMENT_DATA)); | ||
data.snippet = { parentId: commentId, textOriginal: text }; | ||
const response = await this.youtube._request.post('comments', { part: 'id,snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.YTComment(this.youtube, response, true); | ||
} | ||
/** | ||
* Edit a [[Comment]] on a [[Video]] or [[Channel]] discussion. | ||
* Last tested 05/18/2020 11:48. PASSING | ||
* Last tested 07/05/2021 17:40. PASSING | ||
* @param commentId The ID of the comment. | ||
* @param text The new text content of the comment. | ||
* @param commentId The ID of the comment. | ||
*/ | ||
editComment(text, commentId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.COMMENT_THREAD_DATA)); | ||
data.snippet.topLevelComment.snippet.textOriginal = text; | ||
data.id = commentId; | ||
const result = yield this.youtube._request.put('commentThreads', { part: 'snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
const type = result.snippet.channelId ? 'channel' : 'video'; | ||
const comment = new _1.YTComment(this.youtube, result.snippet.topLevelComment, type); | ||
if (result.replies) { | ||
result.replies.comments.forEach(reply => { | ||
const created = new _1.YTComment(this.youtube, reply, type); | ||
comment.replies.push(created); | ||
}); | ||
} | ||
return comment; | ||
}); | ||
async editComment(commentId, text) { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.COMMENT_DATA)); | ||
data.snippet.textOriginal = text; | ||
data.id = commentId; | ||
console.log(data); | ||
const result = await this.youtube._request.put('comments', { part: 'snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
const comment = new _1.YTComment(this.youtube, result, true); | ||
if (result.replies) { | ||
result.replies.comments.forEach(reply => { | ||
const created = new _1.YTComment(this.youtube, reply, true); | ||
comment.replies.push(created); | ||
}); | ||
} | ||
return comment; | ||
} | ||
/** | ||
* Edits a [[YTComment]] reply. | ||
* Last tested 05/18/2020 11:48. PASSING | ||
* @param commentId The ID of the reply to edit. | ||
* @param text The text to edit the reply to. | ||
* @param commentType What this comment is on - defaults to video. | ||
* Required for [[YTComment#url]] to be correct. | ||
*/ | ||
editCommentReply(commentId, text) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.COMMENT_DATA)); | ||
data.id = commentId; | ||
data.snippet.textOriginal = text; | ||
const response = yield this.youtube._request.put('comments', { part: 'id,snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.YTComment(this.youtube, response, response.snippet.channelId ? 'channel' : 'video'); | ||
}); | ||
} | ||
/** | ||
* Marks a [[YTComment]] as spam. | ||
@@ -198,11 +169,9 @@ * Last tested NEVER | ||
*/ | ||
subscribeToChannel(channelResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const channelId = yield services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.SUBSCRIPTION_DATA)); | ||
data.snippet.resourceId.channelId = channelId; | ||
const result = yield this.youtube._request.post('subscriptions', { part: 'snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Subscription(this.youtube, result); | ||
}); | ||
async subscribeToChannel(channelResolvable) { | ||
this.checkTokenAndThrow(); | ||
const channelId = await services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.SUBSCRIPTION_DATA)); | ||
data.snippet.resourceId.channelId = channelId; | ||
const result = await this.youtube._request.post('subscriptions', { part: 'snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Subscription(this.youtube, result); | ||
} | ||
@@ -224,8 +193,6 @@ /** | ||
*/ | ||
rateVideo(videoResolvable, rating) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
return this.youtube._request.post('videos/rate', { id: videoId, rating }, null, null, this.youtube.accessToken); | ||
}); | ||
async rateVideo(videoResolvable, rating) { | ||
this.checkTokenAndThrow(); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
return this.youtube._request.post('videos/rate', { id: videoId, rating }, null, null, this.youtube.accessToken); | ||
} | ||
@@ -237,14 +204,12 @@ /** | ||
*/ | ||
getMyRatings(videoResolvables) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const videoIds = yield Promise.all(videoResolvables.map(videoResolvable => services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video))); | ||
const cached = util_1.Cache.get(`get://videos/getRating/${JSON.stringify(videoIds)}`); | ||
if (this.youtube._shouldCache && cached) { | ||
return cached; | ||
} | ||
const response = yield this.youtube._request.api('videos/getRating', { id: videoIds.join(',') }, null, this.youtube.accessToken); | ||
this.youtube._cache(`get://videos/getRating/${JSON.stringify(videoIds)}`, response.items); | ||
return response.items; | ||
}); | ||
async getMyRatings(videoResolvables) { | ||
this.checkTokenAndThrow(); | ||
const videoIds = await Promise.all(videoResolvables.map(videoResolvable => services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video))); | ||
const cached = util_1.Cache.get(`get://videos/getRating/${JSON.stringify(videoIds)}`); | ||
if (this.youtube._shouldCache && cached) { | ||
return cached; | ||
} | ||
const response = await this.youtube._request.api('videos/getRating', { id: videoIds.join(',') }, null, this.youtube.accessToken); | ||
this.youtube._cache(`get://videos/getRating/${JSON.stringify(videoIds)}`, response.items); | ||
return response.items; | ||
} | ||
@@ -260,18 +225,16 @@ /** | ||
*/ | ||
reportAbuse(videoResolvable, reasonId, secondaryReasonId, comments, language) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = { | ||
videoId, | ||
reasonId | ||
}; | ||
if (secondaryReasonId) | ||
data.secondaryReasonId = secondaryReasonId; | ||
if (comments) | ||
data.comments = comments; | ||
if (language) | ||
data.language = language; | ||
return this.youtube._request.post('videos/reportAbuse', null, JSON.stringify(data), null, this.youtube.accessToken); | ||
}); | ||
async reportAbuse(videoResolvable, reasonId, secondaryReasonId, comments, language) { | ||
this.checkTokenAndThrow(); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = { | ||
videoId, | ||
reasonId | ||
}; | ||
if (secondaryReasonId) | ||
data.secondaryReasonId = secondaryReasonId; | ||
if (comments) | ||
data.comments = comments; | ||
if (language) | ||
data.language = language; | ||
return this.youtube._request.post('videos/reportAbuse', null, JSON.stringify(data), null, this.youtube.accessToken); | ||
} | ||
@@ -283,8 +246,6 @@ /** | ||
*/ | ||
deleteVideo(videoResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
return this.youtube._request.delete('videos', { id: videoId }, null, this.youtube.accessToken); | ||
}); | ||
async deleteVideo(videoResolvable) { | ||
this.checkTokenAndThrow(); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
return this.youtube._request.delete('videos', { id: videoId }, null, this.youtube.accessToken); | ||
} | ||
@@ -298,30 +259,28 @@ /** | ||
*/ | ||
updateVideo(video) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const parts = []; | ||
if (video.snippet) { | ||
parts.push('snippet'); | ||
if (Array.isArray(video.snippet.tags)) | ||
video.snippet.tags = video.snippet.tags.join(','); | ||
async updateVideo(video) { | ||
this.checkTokenAndThrow(); | ||
const parts = []; | ||
if (video.snippet) { | ||
parts.push('snippet'); | ||
if (Array.isArray(video.snippet.tags)) | ||
video.snippet.tags = video.snippet.tags.join(','); | ||
} | ||
if (video.status) { | ||
parts.push('status'); | ||
if (video.status.publishAt instanceof Date) | ||
video.status.publishAt = video.status.publishAt.toISOString(); | ||
} | ||
if (video.recordingDetails) { | ||
parts.push('recordingDetails'); | ||
if (video.recordingDetails.recordingDate instanceof Date) { | ||
video.recordingDetails.recordingDate = video.recordingDetails.recordingDate.toISOString(); | ||
} | ||
if (video.status) { | ||
parts.push('status'); | ||
if (video.status.publishAt instanceof Date) | ||
video.status.publishAt = video.status.publishAt.toISOString(); | ||
} | ||
if (video.recordingDetails) { | ||
parts.push('recordingDetails'); | ||
if (video.recordingDetails.recordingDate instanceof Date) { | ||
video.recordingDetails.recordingDate = video.recordingDetails.recordingDate.toISOString(); | ||
} | ||
} | ||
if (video.localizations) | ||
parts.push('localizations'); | ||
if (parts.length === 0) { | ||
return this.youtube.getVideo(video.id); | ||
} | ||
const response = yield this.youtube._request.put('videos', { part: parts.join(',') }, JSON.stringify(video), null, this.youtube.accessToken); | ||
return new _1.Video(this.youtube, response); | ||
}); | ||
} | ||
if (video.localizations) | ||
parts.push('localizations'); | ||
if (parts.length === 0) { | ||
return this.youtube.getVideo(video.id); | ||
} | ||
const response = await this.youtube._request.put('videos', { part: parts.join(',') }, JSON.stringify(video), null, this.youtube.accessToken); | ||
return new _1.Video(this.youtube, response); | ||
} | ||
@@ -334,9 +293,7 @@ /** | ||
*/ | ||
setThumbnail(videoResolvable, image) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const response = yield this.youtube._upload.imagePost('thumbnails/set', image.data, image.type, { videoId }, null, this.youtube.accessToken); | ||
return response.items[0]; | ||
}); | ||
async setThumbnail(videoResolvable, image) { | ||
this.checkTokenAndThrow(); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const response = await this.youtube._upload.imagePost('thumbnails/set', image.data, image.type, { videoId }, null, this.youtube.accessToken); | ||
return response.items[0]; | ||
} | ||
@@ -353,24 +310,22 @@ /** | ||
*/ | ||
createPlaylist(title, description, privacy, tags, language, localizations) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.PLAYLIST_DATA)); | ||
const parts = ['id', 'player']; | ||
data.snippet = { title }; | ||
data.snippet.defaultLanguage = language ? language : this.youtube.language; | ||
if (description) | ||
data.snippet.description = description; | ||
if (privacy) | ||
data.status = { privacyStatus: privacy }; | ||
if (tags) | ||
data.snippet.tags = tags.join(','); | ||
if (localizations) | ||
data.localizations = localizations; | ||
if (privacy) | ||
parts.push('status'); | ||
if (localizations) | ||
parts.push('localizations'); | ||
const response = yield this.youtube._request.post('playlists', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Playlist(this.youtube, response); | ||
}); | ||
async createPlaylist(title, description, privacy, tags, language, localizations) { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.PLAYLIST_DATA)); | ||
const parts = ['id', 'player']; | ||
data.snippet = { title }; | ||
data.snippet.defaultLanguage = language ? language : this.youtube.language; | ||
if (description) | ||
data.snippet.description = description; | ||
if (privacy) | ||
data.status = { privacyStatus: privacy }; | ||
if (tags) | ||
data.snippet.tags = tags.join(','); | ||
if (localizations) | ||
data.localizations = localizations; | ||
if (privacy) | ||
parts.push('status'); | ||
if (localizations) | ||
parts.push('localizations'); | ||
const response = await this.youtube._request.post('playlists', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Playlist(this.youtube, response); | ||
} | ||
@@ -390,26 +345,24 @@ /** | ||
*/ | ||
updatePlaylist(playlistResolvable, title, description, privacy, tags, language, localizations) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const id = yield services_1.GenericService.getId(this.youtube, playlistResolvable, _1.Playlist); | ||
const data = JSON.parse(JSON.stringify(constants_1.PLAYLIST_DATA)); | ||
const parts = ['id', 'player', 'snippet']; | ||
data.id = id; | ||
data.snippet = { title }; | ||
data.snippet.defaultLanguage = language ? language : this.youtube.language; | ||
if (description) | ||
data.snippet.description = description; | ||
if (privacy) | ||
data.status = { privacyStatus: privacy }; | ||
if (tags) | ||
data.snippet.tags = tags.join(','); | ||
if (localizations) | ||
data.localizations = localizations; | ||
if (privacy) | ||
parts.push('status'); | ||
if (localizations) | ||
parts.push('localizations'); | ||
const response = yield this.youtube._request.put('playlists', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Playlist(this.youtube, response); | ||
}); | ||
async updatePlaylist(playlistResolvable, title, description, privacy, tags, language, localizations) { | ||
this.checkTokenAndThrow(); | ||
const id = await services_1.GenericService.getId(this.youtube, playlistResolvable, _1.Playlist); | ||
const data = JSON.parse(JSON.stringify(constants_1.PLAYLIST_DATA)); | ||
const parts = ['id', 'player', 'snippet']; | ||
data.id = id; | ||
data.snippet = { title }; | ||
data.snippet.defaultLanguage = language ? language : this.youtube.language; | ||
if (description) | ||
data.snippet.description = description; | ||
if (privacy) | ||
data.status = { privacyStatus: privacy }; | ||
if (tags) | ||
data.snippet.tags = tags.join(','); | ||
if (localizations) | ||
data.localizations = localizations; | ||
if (privacy) | ||
parts.push('status'); | ||
if (localizations) | ||
parts.push('localizations'); | ||
const response = await this.youtube._request.put('playlists', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Playlist(this.youtube, response); | ||
} | ||
@@ -421,8 +374,6 @@ /** | ||
*/ | ||
deletePlaylist(playlistResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const id = yield services_1.GenericService.getId(this.youtube, playlistResolvable, _1.Playlist); | ||
return this.youtube._request.delete('playlists', { id }, null, this.youtube.accessToken); | ||
}); | ||
async deletePlaylist(playlistResolvable) { | ||
this.checkTokenAndThrow(); | ||
const id = await services_1.GenericService.getId(this.youtube, playlistResolvable, _1.Playlist); | ||
return this.youtube._request.delete('playlists', { id }, null, this.youtube.accessToken); | ||
} | ||
@@ -438,20 +389,18 @@ /** | ||
*/ | ||
addPlaylistItem(playlistResolvable, videoResolvable, position, note) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const playlistId = yield services_1.GenericService.getId(this.youtube, playlistResolvable, _1.Playlist); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = JSON.parse(JSON.stringify(constants_1.PLAYLIST_ITEM_DATA)); | ||
const parts = ['id', 'snippet']; | ||
data.snippet.playlistId = playlistId; | ||
data.snippet.resourceId.videoId = videoId; | ||
if (position) | ||
data.snippet.position = position; | ||
if (note) | ||
data.contentDetails = { note }; | ||
if (note) | ||
parts.push('contentDetails'); | ||
const response = yield this.youtube._request.post('playlistItems', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Video(this.youtube, response); | ||
}); | ||
async addPlaylistItem(playlistResolvable, videoResolvable, position, note) { | ||
this.checkTokenAndThrow(); | ||
const playlistId = await services_1.GenericService.getId(this.youtube, playlistResolvable, _1.Playlist); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = JSON.parse(JSON.stringify(constants_1.PLAYLIST_ITEM_DATA)); | ||
const parts = ['id', 'snippet']; | ||
data.snippet.playlistId = playlistId; | ||
data.snippet.resourceId.videoId = videoId; | ||
if (position) | ||
data.snippet.position = position; | ||
if (note) | ||
data.contentDetails = { note }; | ||
if (note) | ||
parts.push('contentDetails'); | ||
const response = await this.youtube._request.post('playlistItems', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Video(this.youtube, response); | ||
} | ||
@@ -470,21 +419,19 @@ /** | ||
*/ | ||
updatePlaylistItem(id, playlistResolvable, videoResolvable, position, note) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const playlistId = yield services_1.GenericService.getId(this.youtube, playlistResolvable, _1.Playlist); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = JSON.parse(JSON.stringify(constants_1.PLAYLIST_ITEM_DATA)); | ||
const parts = ['id', 'snippet']; | ||
data.id = id; | ||
data.snippet.playlistId = playlistId; | ||
data.snippet.resourceId.videoId = videoId; | ||
if (position) | ||
data.snippet.position = position; | ||
if (note) | ||
data.contentDetails = { note }; | ||
if (note) | ||
parts.push('contentDetails'); | ||
const response = yield this.youtube._request.put('playlistItems', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Video(this.youtube, response); | ||
}); | ||
async updatePlaylistItem(id, playlistResolvable, videoResolvable, position, note) { | ||
this.checkTokenAndThrow(); | ||
const playlistId = await services_1.GenericService.getId(this.youtube, playlistResolvable, _1.Playlist); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = JSON.parse(JSON.stringify(constants_1.PLAYLIST_ITEM_DATA)); | ||
const parts = ['id', 'snippet']; | ||
data.id = id; | ||
data.snippet.playlistId = playlistId; | ||
data.snippet.resourceId.videoId = videoId; | ||
if (position) | ||
data.snippet.position = position; | ||
if (note) | ||
data.contentDetails = { note }; | ||
if (note) | ||
parts.push('contentDetails'); | ||
const response = await this.youtube._request.put('playlistItems', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Video(this.youtube, response); | ||
} | ||
@@ -508,12 +455,10 @@ /** | ||
*/ | ||
updateChannelBranding(channelResolvable, brandingSettings) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const id = yield services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_DATA)); | ||
data.id = id; | ||
data.brandingSettings = brandingSettings; | ||
const response = yield this.youtube._request.put('channels', { part: 'brandingSettings' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Channel(this.youtube, response); | ||
}); | ||
async updateChannelBranding(channelResolvable, brandingSettings) { | ||
this.checkTokenAndThrow(); | ||
const id = await services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_DATA)); | ||
data.id = id; | ||
data.brandingSettings = brandingSettings; | ||
const response = await this.youtube._request.put('channels', { part: 'brandingSettings' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Channel(this.youtube, response); | ||
} | ||
@@ -528,12 +473,10 @@ /** | ||
*/ | ||
updateChannelLocalizations(channelResolvable, localizations) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const id = yield services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_DATA)); | ||
data.id = id; | ||
data.localizations = localizations; | ||
const response = yield this.youtube._request.put('channels', { part: 'localizations' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Channel(this.youtube, response); | ||
}); | ||
async updateChannelLocalizations(channelResolvable, localizations) { | ||
this.checkTokenAndThrow(); | ||
const id = await services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_DATA)); | ||
data.id = id; | ||
data.localizations = localizations; | ||
const response = await this.youtube._request.put('channels', { part: 'localizations' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Channel(this.youtube, response); | ||
} | ||
@@ -546,14 +489,12 @@ /** | ||
*/ | ||
setChannelMadeForKids(channelResolvable, madeForKids) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const id = yield services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_DATA)); | ||
data.id = id; | ||
data.status = { | ||
selfDeclaredMadeForKids: madeForKids | ||
}; | ||
const response = yield this.youtube._request.put('channels', { part: 'status' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Channel(this.youtube, response); | ||
}); | ||
async setChannelMadeForKids(channelResolvable, madeForKids) { | ||
this.checkTokenAndThrow(); | ||
const id = await services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_DATA)); | ||
data.id = id; | ||
data.status = { | ||
selfDeclaredMadeForKids: madeForKids | ||
}; | ||
const response = await this.youtube._request.put('channels', { part: 'status' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.Channel(this.youtube, response); | ||
} | ||
@@ -569,14 +510,12 @@ /** | ||
*/ | ||
setChannelWatermark(channelResolvable, type, offset, duration, image, imageType) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const id = yield services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.WATERMARK_DATA)); | ||
data.timing = { | ||
type: type === 'fromStart' ? 'offsetFromStart' : 'offsetFromEnd', | ||
offsetMs: offset, | ||
durationMs: duration | ||
}; | ||
return this.youtube._upload.multipartImagePost('watermarks/set', JSON.stringify(data), image, imageType, { channelId: id }, null, this.youtube.accessToken); | ||
}); | ||
async setChannelWatermark(channelResolvable, type, offset, duration, image, imageType) { | ||
this.checkTokenAndThrow(); | ||
const id = await services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
const data = JSON.parse(JSON.stringify(constants_1.WATERMARK_DATA)); | ||
data.timing = { | ||
type: type === 'fromStart' ? 'offsetFromStart' : 'offsetFromEnd', | ||
offsetMs: offset, | ||
durationMs: duration | ||
}; | ||
return this.youtube._upload.multipartImagePost('watermarks/set', JSON.stringify(data), image, imageType, { channelId: id }, null, this.youtube.accessToken); | ||
} | ||
@@ -588,8 +527,6 @@ /** | ||
*/ | ||
unsetChannelWatermark(channelResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const id = yield services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
return this.youtube._request.post('watermarks/unset', { channelId: id }, null, null, this.youtube.accessToken); | ||
}); | ||
async unsetChannelWatermark(channelResolvable) { | ||
this.checkTokenAndThrow(); | ||
const id = await services_1.GenericService.getId(this.youtube, channelResolvable, _1.Channel); | ||
return this.youtube._request.post('watermarks/unset', { channelId: id }, null, null, this.youtube.accessToken); | ||
} | ||
@@ -601,10 +538,8 @@ /** | ||
* @returns The URL of the uploaded banner, used as | ||
* [[BrandingSettings#image#bannerExternalUrl]] in [[OAuth#updateChannelBranding]] | ||
* [[BrandingSettings.image.bannerExternalUrl]] in [[OAuth.updateChannelBranding]] | ||
*/ | ||
uploadChannelBanner(image) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const response = yield this.youtube._upload.imagePost('channelBanners/insert', image.data, image.type, null, null, this.youtube.accessToken); | ||
return response.url; | ||
}); | ||
async uploadChannelBanner(image) { | ||
this.checkTokenAndThrow(); | ||
const response = await this.youtube._upload.imagePost('channelBanners/insert', image.data, image.type, null, null, this.youtube.accessToken); | ||
return response.url; | ||
} | ||
@@ -615,41 +550,26 @@ /** | ||
* @param type The type of channel section. | ||
* @param style The style of the channel section. | ||
* @param name The name of the channel section. | ||
* @param position The position of the channel section on the channel homepage. | ||
* @param language The default language of the channel section. | ||
* @param playlistsResolvable Any playlists in the channel section. | ||
* @param channelsResolvable Any channels in the channel section. | ||
* @param localizations Translations of the channel section's title. | ||
* @param targeting Targeting data for the channel section. | ||
*/ | ||
addChannelSection(type, style, name, language, playlistsResolvable, channelsResolvable, localizations, targeting) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_SECTION_DATA)); | ||
const parts = ['id', 'snippet']; | ||
data.snippet.type = type; | ||
data.snippet.style = style; | ||
if (name) | ||
data.snippet.title = name; | ||
if (language) | ||
data.snippet.defaultLanguage = language; | ||
if (playlistsResolvable || channelsResolvable) | ||
data.contentDetails = {}; | ||
if (playlistsResolvable) | ||
data.contentDetails.playlists = yield Promise.all(playlistsResolvable.map(v => services_1.GenericService.getId(this.youtube, v, _1.Playlist))); | ||
if (channelsResolvable) | ||
data.contentDetails.channels = yield Promise.all(channelsResolvable.map(v => services_1.GenericService.getId(this.youtube, v, _1.Channel))); | ||
if (localizations) | ||
data.localizations = localizations; | ||
if (targeting) | ||
data.targeting = targeting; | ||
if (playlistsResolvable || channelsResolvable) | ||
parts.push('contentDetails'); | ||
if (localizations) | ||
parts.push('localizations'); | ||
if (targeting) | ||
parts.push('targeting'); | ||
const response = yield this.youtube._request.post('channelSections', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.ChannelSection(this.youtube, response); | ||
}); | ||
async addChannelSection(type, name, position, playlistsResolvable, channelsResolvable) { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_SECTION_DATA)); | ||
const parts = ['id', 'snippet']; | ||
data.snippet.type = type; | ||
if (name) | ||
data.snippet.title = name; | ||
if (position) | ||
data.snippet.position = position; | ||
if (playlistsResolvable || channelsResolvable) | ||
data.contentDetails = {}; | ||
if (playlistsResolvable) | ||
data.contentDetails.playlists = await Promise.all(playlistsResolvable.map(v => services_1.GenericService.getId(this.youtube, v, _1.Playlist))); | ||
if (channelsResolvable) | ||
data.contentDetails.channels = await Promise.all(channelsResolvable.map(v => services_1.GenericService.getId(this.youtube, v, _1.Channel))); | ||
if (playlistsResolvable || channelsResolvable) | ||
parts.push('contentDetails'); | ||
const response = await this.youtube._request.post('channelSections', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.ChannelSection(this.youtube, response); | ||
} | ||
@@ -672,35 +592,22 @@ /** | ||
*/ | ||
updateChannelSection(id, type, style, name, position, language, playlistsResolvable, channelsResolvable, localizations, targeting) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_SECTION_DATA)); | ||
const parts = ['id', 'snippet']; | ||
data.id = id; | ||
data.snippet.type = type; | ||
data.snippet.style = style; | ||
if (name) | ||
data.snippet.title = name; | ||
if (position) | ||
data.snippet.position = position; | ||
if (language) | ||
data.snippet.defaultLanguage = language; | ||
if (playlistsResolvable || channelsResolvable) | ||
data.contentDetails = {}; | ||
if (playlistsResolvable) | ||
data.contentDetails.playlists = yield Promise.all(playlistsResolvable.map(v => services_1.GenericService.getId(this.youtube, v, _1.Playlist))); | ||
if (channelsResolvable) | ||
data.contentDetails.channels = yield Promise.all(channelsResolvable.map(v => services_1.GenericService.getId(this.youtube, v, _1.Channel))); | ||
if (localizations) | ||
data.localizations = localizations; | ||
if (targeting) | ||
data.targeting = targeting; | ||
if (playlistsResolvable || channelsResolvable) | ||
parts.push('contentDetails'); | ||
if (localizations) | ||
parts.push('localizations'); | ||
if (targeting) | ||
parts.push('targeting'); | ||
const response = yield this.youtube._request.put('channelSections', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.ChannelSection(this.youtube, response); | ||
}); | ||
async updateChannelSection(id, type, name, position, playlistsResolvable, channelsResolvable) { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.CHANNEL_SECTION_DATA)); | ||
const parts = ['id', 'snippet']; | ||
data.id = id; | ||
data.snippet.type = type; | ||
if (name) | ||
data.snippet.title = name; | ||
if (position) | ||
data.snippet.position = position; | ||
if (playlistsResolvable || channelsResolvable) | ||
data.contentDetails = {}; | ||
if (playlistsResolvable) | ||
data.contentDetails.playlists = await Promise.all(playlistsResolvable.map(v => services_1.GenericService.getId(this.youtube, v, _1.Playlist))); | ||
if (channelsResolvable) | ||
data.contentDetails.channels = await Promise.all(channelsResolvable.map(v => services_1.GenericService.getId(this.youtube, v, _1.Channel))); | ||
if (playlistsResolvable || channelsResolvable) | ||
parts.push('contentDetails'); | ||
const response = await this.youtube._request.put('channelSections', { part: parts.join(',') }, JSON.stringify(data), null, this.youtube.accessToken); | ||
return new _1.ChannelSection(this.youtube, response); | ||
} | ||
@@ -722,28 +629,24 @@ /** | ||
*/ | ||
getCaption(videoResolvable, captionId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = yield this.youtube._request.api('captions', { videoId, id: captionId, part: 'snippet' }, null, this.youtube.accessToken); | ||
if (!data.items || data.items.length === 0) { | ||
return Promise.reject('Caption not found'); | ||
} | ||
return new _1.Caption(this.youtube, data.items[0]); | ||
}); | ||
async getCaption(videoResolvable, captionId) { | ||
this.checkTokenAndThrow(); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = await this.youtube._request.api('captions', { videoId, id: captionId, part: 'snippet' }, null, this.youtube.accessToken); | ||
if (!data.items || data.items.length === 0) { | ||
return Promise.reject('Caption not found'); | ||
} | ||
return new _1.Caption(this.youtube, data.items[0]); | ||
} | ||
/** | ||
* Gets the [[Caption]]s of a [[Video]]. Used mostly internally with [[Video#fetchCaptions]]. | ||
* Gets the [[Caption]]s of a [[Video]]. Used mostly internally with [[Video.fetchCaptions]]. | ||
* Last tested 06/11/2020 04:50. PASSING | ||
* @param videoResolvable The Title, URL, or ID of the video to get the captions from. | ||
*/ | ||
getCaptions(videoResolvable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = yield this.youtube._request.api('captions', { videoId, part: 'snippet' }, null, this.youtube.accessToken); | ||
if (!data.items || data.items.length === 0) { | ||
return Promise.reject('Captions not found'); | ||
} | ||
return data.items.map(caption => new _1.Caption(this.youtube, caption)); | ||
}); | ||
async getCaptions(videoResolvable) { | ||
this.checkTokenAndThrow(); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = await this.youtube._request.api('captions', { videoId, part: 'snippet' }, null, this.youtube.accessToken); | ||
if (!data.items || data.items.length === 0) { | ||
return Promise.reject('Captions not found'); | ||
} | ||
return data.items.map(caption => new _1.Caption(this.youtube, caption)); | ||
} | ||
@@ -759,16 +662,14 @@ /** | ||
*/ | ||
uploadCaption(videoResolvable, language, name, track, draft = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const videoId = yield services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = JSON.parse(JSON.stringify(constants_1.CAPTION_DATA)); | ||
data.snippet = { | ||
videoId: videoId, | ||
language: language, | ||
name: name, | ||
isDraft: draft | ||
}; | ||
const response = yield this.youtube._upload.multipartStreamPost('captions', JSON.stringify(data), track, { part: 'snippet' }, null, this.youtube.accessToken); | ||
return new _1.Caption(this.youtube, response); | ||
}); | ||
async uploadCaption(videoResolvable, language, name, track, draft = false) { | ||
this.checkTokenAndThrow(); | ||
const videoId = await services_1.GenericService.getId(this.youtube, videoResolvable, _1.Video); | ||
const data = JSON.parse(JSON.stringify(constants_1.CAPTION_DATA)); | ||
data.snippet = { | ||
videoId: videoId, | ||
language: language, | ||
name: name, | ||
isDraft: draft | ||
}; | ||
const response = await this.youtube._upload.multipartStreamPost('captions', JSON.stringify(data), track, { part: 'snippet' }, null, this.youtube.accessToken); | ||
return new _1.Caption(this.youtube, response); | ||
} | ||
@@ -784,22 +685,20 @@ /** | ||
*/ | ||
updateCaption(id, track, draft = null) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.CAPTION_DATA)); | ||
data.id = id; | ||
data.snippet = { isDraft: draft }; | ||
let response; | ||
if (track) { | ||
if (draft !== null) { | ||
response = yield this.youtube._upload.multipartStreamPut('captions', JSON.stringify(data), track, { part: 'snippet' }, null, this.youtube.accessToken); | ||
} | ||
else { | ||
response = yield this.youtube._upload.streamPut('captions', track, { part: 'snippet' }, null, this.youtube.accessToken); | ||
} | ||
async updateCaption(id, track, draft = null) { | ||
this.checkTokenAndThrow(); | ||
const data = JSON.parse(JSON.stringify(constants_1.CAPTION_DATA)); | ||
data.id = id; | ||
data.snippet = { isDraft: draft }; | ||
let response; | ||
if (track) { | ||
if (draft !== null) { | ||
response = await this.youtube._upload.multipartStreamPut('captions', JSON.stringify(data), track, { part: 'snippet' }, null, this.youtube.accessToken); | ||
} | ||
else { | ||
response = yield this.youtube._request.put('captions', { part: 'snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
response = await this.youtube._upload.streamPut('captions', track, { part: 'snippet' }, null, this.youtube.accessToken); | ||
} | ||
return new _1.Caption(this.youtube, response); | ||
}); | ||
} | ||
else { | ||
response = await this.youtube._request.put('captions', { part: 'snippet' }, JSON.stringify(data), null, this.youtube.accessToken); | ||
} | ||
return new _1.Caption(this.youtube, response); | ||
} | ||
@@ -837,5 +736,5 @@ /** | ||
*/ | ||
getVideoAbuseReportReasons() { | ||
async getVideoAbuseReportReasons() { | ||
this.checkTokenAndThrow(); | ||
return services_1.GenericService.getPaginatedItems(this.youtube, 'videoAbuseReportReasons', false); | ||
return (await services_1.GenericService.getPaginatedItems({ youtube: this.youtube, type: _1.PaginatedItemType.VideoAbuseReportReasons })).results; | ||
} | ||
@@ -842,0 +741,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,2 +6,3 @@ exports.GenericService = void 0; | ||
const util_1 = require("../util"); | ||
const types_1 = require("../types"); | ||
/** | ||
@@ -21,88 +13,119 @@ * @ignore | ||
/* istanbul ignore next */ | ||
static getItem(youtube, type, mine, id) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!([__1.Video, __1.Channel, __1.Playlist, __1.YTComment, __1.Subscription, __1.VideoCategory, __1.VideoAbuseReportReason, __1.ChannelSection, __1.Caption].includes(type))) { | ||
return Promise.reject('Type must be a video, channel, playlist, comment, subscription, video category, or channel section.'); | ||
} | ||
if (!mine && (id === undefined || id === null)) { | ||
return Promise.reject('Items must either specify an ID or the \'mine\' parameter.'); | ||
} | ||
if (mine && ['comments', 'videos', 'guideCategories', 'videoAbuseReportReasons', 'videoCategories', 'playlistItems'].includes(type.endpoint)) { | ||
return Promise.reject(`${type.endpoint} cannot be filtered by the 'mine' parameter.`); | ||
} | ||
static async getItem(youtube, type, mine, id, parts) { | ||
if (!([__1.Video, __1.Channel, __1.Playlist, __1.YTComment, __1.Subscription, __1.VideoCategory, __1.VideoAbuseReportReason, __1.ChannelSection, __1.Caption].includes(type))) { | ||
return Promise.reject(`${type.name}s cannot be directly fetched. The item may be paginated or not directly accessible.`); | ||
} | ||
if (!mine && id == null) { | ||
return Promise.reject('Items must either specify an ID or the \'mine\' parameter.'); | ||
} | ||
if (mine && ['comments', 'videos', 'guideCategories', 'videoAbuseReportReasons', 'videoCategories', 'playlistItems'].includes(type.endpoint)) { | ||
return Promise.reject(`${type.endpoint} cannot be filtered by the 'mine' parameter.`); | ||
} | ||
if (youtube._shouldCache) { | ||
const cached = util_1.Cache.get(`get://${type.endpoint}/${id ? id : 'mine'}`); | ||
if (youtube._shouldCache && cached) { | ||
if (cached) | ||
return cached; | ||
} | ||
const params = { | ||
[id ? 'id' : 'mine']: id ? id : mine, | ||
fields: encodeURIComponent(type.fields), | ||
part: type === __1.YTComment ? !type.part.includes('snippet') ? type.part + ',snippet' : type.part : type.part | ||
}; | ||
if (type === __1.VideoCategory) { | ||
params.hl = youtube.language; | ||
} | ||
const result = yield youtube._request.api(type.endpoint, params, youtube.token, youtube.accessToken); | ||
if (!result.items || result.items.length === 0) { | ||
return Promise.reject('Item not found'); | ||
} | ||
let endResult; | ||
if (type === __1.YTComment) { | ||
endResult = new type(youtube, result.items[0], result.items[0].snippet.channelId ? 'channel' : 'video'); | ||
} | ||
else { | ||
endResult = new type(youtube, result.items[0]); | ||
} | ||
} | ||
const params = { | ||
[id ? 'id' : 'mine']: id ? id : mine, | ||
fields: encodeURIComponent(type.fields), | ||
part: type === __1.YTComment ? 'snippet' : parts ? parts.join(',') : type.part | ||
}; | ||
if (type === __1.VideoCategory) { | ||
params.hl = youtube.language; | ||
} | ||
const result = await youtube._request.api(type.endpoint, params, youtube.token, youtube.accessToken); | ||
if (!result.items || result.items.length === 0) { | ||
return Promise.reject('Item not found'); | ||
} | ||
let endResult = new (type)(youtube, result.items[0], true); | ||
endResult.full = true; | ||
if (youtube._shouldCache) | ||
youtube._cache(`get://${type.endpoint}/${id ? id : 'mine'}`, endResult); | ||
return endResult; | ||
}); | ||
return endResult; | ||
} | ||
/** | ||
* | ||
* @param maxPerPage Leave undefined or set to < 1 to fetch the maximum allowed by the API for any given type. | ||
* @param pages Number of pages to fetch from the API. Set to < 1 to fetch all of them. Defaults to 1. | ||
* @param pageToken The page to start at (retrieved from the return value of a previous call to this function) | ||
* | ||
* @returns An object containing the array of instantiated entities as well as possible next and previous page tokens. | ||
*/ | ||
/* istanbul ignore next */ | ||
static getPaginatedItems(youtube, endpoint, mine, id, maxResults = -1, subId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!mine && (id === undefined || id === null) && | ||
!(['videoAbuseReportReasons', 'i18nLanguages', 'i18nRegions', 'videoCategories'].includes(endpoint))) { | ||
return Promise.reject(`${endpoint} must either specify an ID or the 'mine' parameter.`); | ||
} | ||
if (mine && (endpoint.startsWith('comment') || | ||
['playlistItems', 'videoCategories', 'videoAbuseReportReasons', 'i18nLanguages', 'i18nRegions', 'captions'].includes(endpoint))) { | ||
return Promise.reject(`${endpoint} cannot be filtered by the 'mine' parameter.`); | ||
} | ||
const cached = util_1.Cache.get(`get://${endpoint}/${id ? id : 'mine'}/${maxResults}`); | ||
if (youtube._shouldCache && cached) { | ||
static async getPaginatedItems({ youtube, type, mine = false, id, maxPerPage = 0, pages = 1, pageToken, subId, parts }) { | ||
const name = types_1.PaginatedItemType[type]; | ||
// These four types in the PaginatedItemTypes enum don't require any sort of identification parameter | ||
if (!mine && id == null && | ||
!['VideoCategories', 'VideoAbuseReportReasons', 'Languages', 'Regions'].includes(name)) { | ||
return Promise.reject(`${name} must either specify an ID or the 'mine' parameter.`); | ||
} | ||
// These three types in the PaginatedItemTypes enum are the only to be filtered by the 'mine' parameter | ||
if (mine && !['Playlists', 'Subscriptions', 'ChannelSections'].includes(name)) { | ||
return Promise.reject(`${name} cannot be filtered by the 'mine' parameter.`); | ||
} | ||
if (youtube._shouldCache) { | ||
const cached = util_1.Cache.get(`getpage://${type}/${mine}/${id}/${subId}/${parts?.join(',')}/${pages < 1 ? maxPerPage : 0}/${pages}/${pageToken}`); | ||
if (cached) | ||
return cached; | ||
} | ||
let items = []; | ||
const full = maxResults <= 0; | ||
const options = { | ||
part: 'snippet' | ||
}; | ||
let max; | ||
let clazz; | ||
let commentType; | ||
if (endpoint === 'playlistItems') { | ||
max = 50; | ||
} | ||
const options = { | ||
part: parts ? parts.join(',') : 'snippet' | ||
}; | ||
let endpoint; | ||
let maxForEndpoint; | ||
let clazz; | ||
let commentType; | ||
// MUST specify endpoint and clazz values, and most likely need a max as well | ||
switch (type) { | ||
case types_1.PaginatedItemType.PlaylistItems: | ||
endpoint = 'playlistItems'; | ||
maxForEndpoint = 50; | ||
clazz = __1.Video; | ||
options.playlistId = id; | ||
if (!options.part.includes('snippet')) | ||
options.part += ',snippet'; | ||
if (subId) | ||
options.videoId = subId; | ||
} | ||
else if (endpoint.startsWith('commentThreads')) { | ||
max = 100; | ||
break; | ||
case types_1.PaginatedItemType.VideoComments: | ||
commentType = 'video'; | ||
// falls through | ||
case types_1.PaginatedItemType.ChannelComments: | ||
if (!commentType) | ||
commentType = 'channel'; | ||
endpoint = 'commentThreads'; | ||
maxForEndpoint = 100; | ||
clazz = __1.YTComment; | ||
const [, type] = endpoint.split(':'); | ||
commentType = type ? type : 'video'; | ||
endpoint = 'commentThreads'; | ||
options[`${type}Id`] = id; | ||
options[`${commentType}Id`] = id; | ||
if (!options.part.includes('snippet')) | ||
options.part += ',snippet'; | ||
if (!options.part.includes('replies')) | ||
options.part += ',replies'; | ||
options.textFormat = 'plainText'; | ||
} | ||
else if (endpoint === 'comments') { | ||
max = 100; | ||
break; | ||
case types_1.PaginatedItemType.CommentReplies: | ||
endpoint = 'comments'; | ||
maxForEndpoint = 100; | ||
clazz = __1.YTComment; | ||
options.parentId = id; | ||
} | ||
else if (endpoint === 'playlists:channel') { | ||
max = 50; | ||
if (!options.part.includes('snippet')) | ||
options.part += ',snippet'; | ||
break; | ||
case types_1.PaginatedItemType.Playlists: | ||
endpoint = 'playlists'; | ||
clazz = __1.Playlist; | ||
endpoint = 'playlists'; | ||
// falls through | ||
case types_1.PaginatedItemType.Subscriptions: | ||
if (!endpoint) | ||
endpoint = 'subscriptions'; | ||
if (!clazz) | ||
clazz = __1.Subscription; | ||
maxForEndpoint = 50; | ||
// falls through | ||
case types_1.PaginatedItemType.ChannelSections: | ||
if (!endpoint) | ||
endpoint = 'channelSections'; | ||
if (!clazz) | ||
clazz = __1.ChannelSection; | ||
if (mine) | ||
@@ -112,142 +135,140 @@ options.mine = mine; | ||
options.channelId = id; | ||
} | ||
else if (endpoint === 'subscriptions') { | ||
max = 50; | ||
clazz = __1.Subscription; | ||
if (mine) | ||
options.mine = mine; | ||
else | ||
options.channelId = id; | ||
} | ||
else if (endpoint === 'videoCategories') { | ||
break; | ||
case types_1.PaginatedItemType.VideoCategories: | ||
endpoint = 'videoCategories'; | ||
clazz = __1.VideoCategory; | ||
options.regionCode = youtube.region; | ||
// falls through | ||
case types_1.PaginatedItemType.VideoAbuseReportReasons: | ||
if (!endpoint) | ||
endpoint = 'videoAbuseReportReasons'; | ||
if (!clazz) | ||
clazz = __1.VideoAbuseReportReason; | ||
// falls through | ||
case types_1.PaginatedItemType.Languages: | ||
if (!endpoint) | ||
endpoint = 'i18nLanguages'; | ||
if (!clazz) | ||
clazz = __1.Language; | ||
// falls through | ||
case types_1.PaginatedItemType.Regions: | ||
if (!endpoint) | ||
endpoint = 'i18nRegions'; | ||
if (!clazz) | ||
clazz = __1.Region; | ||
options.hl = youtube.language; | ||
} | ||
else if (endpoint === 'videoAbuseReportReasons' || endpoint === 'i18nLanguages' || endpoint === 'i18nRegions') { | ||
clazz = endpoint === 'videoAbuseReportReasons' ? __1.VideoAbuseReportReason : (endpoint === 'i18nLanguages' ? __1.Language : __1.Region); | ||
options.hl = youtube.language; | ||
} | ||
else if (endpoint === 'channelSections') { | ||
clazz = __1.ChannelSection; | ||
if (mine) | ||
options.mine = mine; | ||
else | ||
options.channelId = id; | ||
} | ||
else if (endpoint === 'captions') { | ||
break; | ||
case types_1.PaginatedItemType.Captions: | ||
endpoint = 'captions'; | ||
clazz = __1.Caption; | ||
options.videoId = id; | ||
break; | ||
default: | ||
return Promise.reject('Unknown item type: ' + type); | ||
} | ||
if (maxForEndpoint !== undefined) { | ||
if (pages < 1 || maxPerPage < 1) | ||
options.maxResults = maxForEndpoint; | ||
else if (maxPerPage > maxForEndpoint) | ||
return Promise.reject(`Max results must be ${maxForEndpoint} or below for ${endpoint}`); | ||
else | ||
options.maxResults = maxPerPage; | ||
} | ||
if (pageToken) | ||
options.pageToken = pageToken; | ||
if (pages < 1) { | ||
pages = Infinity; | ||
} | ||
const toReturn = { | ||
results: [] | ||
}; | ||
let pagesFetched = 0; | ||
let apiResponse; | ||
while (true) { | ||
apiResponse = await youtube._request.api(endpoint, options, youtube.token, youtube.accessToken); | ||
if (!apiResponse.items?.length) { | ||
if (apiResponse.prevPageToken) | ||
toReturn.prevPageToken = apiResponse.prevPageToken; | ||
break; | ||
} | ||
else { | ||
return Promise.reject('Unknown item type ' + endpoint); | ||
} | ||
if (max && maxResults > max) { | ||
return Promise.reject(`Max results must be ${max} or below for ${endpoint}`); | ||
} | ||
if (max) { | ||
options.maxResults = full ? max : maxResults; | ||
} | ||
let results; | ||
let pages = -1; | ||
let shouldReturn = !full; | ||
for (let i = 1; i < (pages > 0 ? pages : 3); i++) { | ||
results = yield youtube._request.api(endpoint, options, youtube.token, youtube.accessToken); | ||
if (results.items.length === 0) { | ||
return Promise.reject(`${endpoint} not found`); | ||
pagesFetched++; | ||
for (const data of apiResponse.items) { | ||
if (data.kind === 'youtube#commentThread') { | ||
toReturn.results.push(new __1.YTComment(youtube, data.snippet.topLevelComment, true, data.replies?.comments)); | ||
} | ||
if (pages < 1) { | ||
pages = results.pageInfo ? results.pageInfo.totalResults / results.pageInfo.resultsPerPage : 0; | ||
if (pages <= 1) { | ||
shouldReturn = true; | ||
} | ||
pages = Math.floor(pages); | ||
} | ||
for (let i = 0; i < results.items.length; i++) { | ||
const item = results.items[i]; | ||
let comment; | ||
if (item.snippet.topLevelComment) { | ||
comment = new __1.YTComment(youtube, item.snippet.topLevelComment, commentType); | ||
items.push(comment); | ||
} | ||
else { | ||
items.push(new clazz(youtube, item, commentType)); | ||
} | ||
if (item.replies) { | ||
item.replies.comments.forEach(reply => { | ||
const created = new __1.YTComment(youtube, reply, commentType); | ||
comment.replies.push(created); | ||
}); | ||
} | ||
} | ||
if (results.nextPageToken && !shouldReturn) { | ||
options.pageToken = results.nextPageToken; | ||
} | ||
else { | ||
return items; | ||
toReturn.results.push(new clazz(youtube, data, false)); | ||
} | ||
} | ||
youtube._cache(`get://${endpoint}/${id ? id : 'mine'}/${maxResults}`, items); | ||
return items; | ||
}); | ||
if (pagesFetched >= pages || !apiResponse.nextPageToken) { | ||
if (apiResponse.prevPageToken) | ||
toReturn.prevPageToken = apiResponse.prevPageToken; | ||
if (apiResponse.nextPageToken) | ||
toReturn.nextPageToken = apiResponse.nextPageToken; | ||
break; | ||
} | ||
options.pageToken = apiResponse.nextPageToken; | ||
} | ||
if (youtube._shouldCache) | ||
youtube._cache(`getpage://${type}/${id ? id : 'mine'}/${subId}/${parts?.join(',')}/${maxPerPage}/${pages}/${pageToken}`, toReturn); | ||
return toReturn; | ||
} | ||
/* istanbul ignore next */ | ||
static getId(youtube, input, type) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let id = null; | ||
const cached = util_1.Cache.get(`get_id://${type.endpoint}/${input}`); | ||
if (cached) { | ||
return cached; | ||
} | ||
const cachedEntity = util_1.Cache.get(`get://${type.endpoint}/${input}`); | ||
if (cachedEntity && cachedEntity.id) { | ||
return cachedEntity.id; | ||
} | ||
if (typeof input !== 'string') { | ||
return input.id; | ||
} | ||
if (input.includes('youtube.com') || input.includes('youtu.be')) { | ||
id = util_1.Parser.parseUrl(input)[type.name.toLowerCase()]; | ||
// Custom channel URLs don't work that well | ||
if (type === __1.Channel && id && !id.startsWith('UC')) { | ||
id = yield youtube._request.api('search', { | ||
q: encodeURIComponent(id), | ||
type: 'channel', | ||
part: 'id', | ||
maxResults: 1 | ||
}, youtube.token, youtube.accessToken).then(r => r.items[0] ? r.items[0].id.channelId : undefined); | ||
} | ||
} | ||
if (id !== null && id !== undefined && id !== '') { | ||
return id; | ||
} | ||
if (type === __1.Channel && (!input.startsWith('UC') || input.includes(' '))) { | ||
id = yield youtube._request.api('search', { | ||
q: encodeURIComponent(input), | ||
static async getId(youtube, input, type) { | ||
let id = null; | ||
const cached = util_1.Cache.get(`get_id://${type.endpoint}/${input}`); | ||
if (cached) { | ||
return cached; | ||
} | ||
const cachedEntity = util_1.Cache.get(`get://${type.endpoint}/${input}`); | ||
if (cachedEntity && cachedEntity.id) { | ||
return cachedEntity.id; | ||
} | ||
if (typeof input !== 'string') { | ||
return input.id; | ||
} | ||
if (input.includes('youtube.com') || input.includes('youtu.be')) { | ||
id = util_1.Parser.parseUrl(input)[type.name.toLowerCase()]; | ||
// Custom channel URLs don't work that well | ||
if (type === __1.Channel && id && !id.startsWith('UC')) { | ||
id = await youtube._request.api('search', { | ||
q: encodeURIComponent(id), | ||
type: 'channel', | ||
part: 'id', maxResults: 1 | ||
}, youtube.token, youtube.accessToken).then(r => r.items ? (r.items.length > 0 ? r.items[0].id.channelId : undefined) : undefined); | ||
} | ||
else if (type === __1.Playlist && input.includes(' ')) { | ||
id = yield youtube._request.api('search', { | ||
q: encodeURIComponent(input), | ||
type: 'playlist', | ||
part: 'id', | ||
maxResults: 1 | ||
}, youtube.token, youtube.accessToken).then(r => r.items ? (r.items.length > 0 ? r.items[0].id.playlistId : undefined) : undefined); | ||
}, youtube.token, youtube.accessToken).then(r => r.items[0] ? r.items[0].id.channelId : undefined); | ||
} | ||
else if (type === __1.Video && (input.length < 11 || input.includes(' '))) { | ||
id = yield youtube._request.api('search', { | ||
q: encodeURIComponent(input), | ||
type: 'video', | ||
part: 'id', | ||
maxResults: 1 | ||
}, youtube.token, youtube.accessToken).then(r => r.items ? (r.items.length > 0 ? r.items[0].id.videoId : undefined) : undefined); | ||
} | ||
if (id === null || id === undefined || id === '') { | ||
id = input; | ||
} | ||
youtube._cache(`get_id://${type.endpoint}/${input}`, id); | ||
} | ||
if (id !== null && id !== undefined && id !== '') { | ||
return id; | ||
}); | ||
} | ||
if (type === __1.Channel && (!input.startsWith('UC') || input.includes(' '))) { | ||
id = await youtube._request.api('search', { | ||
q: encodeURIComponent(input), | ||
type: 'channel', | ||
part: 'id', | ||
maxResults: 1 | ||
}, youtube.token, youtube.accessToken).then(r => r.items ? (r.items.length > 0 ? r.items[0].id.channelId : undefined) : undefined); | ||
} | ||
else if (type === __1.Playlist && input.includes(' ')) { | ||
id = await youtube._request.api('search', { | ||
q: encodeURIComponent(input), | ||
type: 'playlist', | ||
part: 'id', | ||
maxResults: 1 | ||
}, youtube.token, youtube.accessToken).then(r => r.items ? (r.items.length > 0 ? r.items[0].id.playlistId : undefined) : undefined); | ||
} | ||
else if (type === __1.Video && (input.length < 11 || input.includes(' '))) { | ||
id = await youtube._request.api('search', { | ||
q: encodeURIComponent(input), | ||
type: 'video', | ||
part: 'id', | ||
maxResults: 1 | ||
}, youtube.token, youtube.accessToken).then(r => r.items ? (r.items.length > 0 ? r.items[0].id.videoId : undefined) : undefined); | ||
} | ||
if (id === null || id === undefined || id === '') { | ||
id = input; | ||
} | ||
youtube._cache(`get_id://${type.endpoint}/${input}`, id); | ||
return id; | ||
} | ||
@@ -254,0 +275,0 @@ } |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,58 +11,57 @@ exports.SearchService = void 0; | ||
/* istanbul ignore next */ | ||
static search(youtube, types, searchTerm, maxResults = 10, pageToken, channelId, fields, category, onlyEmbeddable = false, eventType, videoType) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const type = types.map(t => t.endpoint.substring(0, t.endpoint.length - 1)).join(','); | ||
static async search(youtube, types, searchTerm, maxResults = 10, pageToken, channelId, fields, category, onlyEmbeddable = false, eventType, videoType) { | ||
const type = types.map(t => t.name.toLowerCase()).join(','); | ||
if (youtube._shouldCache) { | ||
const cached = util_1.Cache.get(`search://${type}/"${searchTerm}"/${maxResults}/"${pageToken}"`); | ||
if (youtube._shouldCache && cached) { | ||
if (cached) | ||
return cached; | ||
} | ||
if (maxResults < 1 || maxResults > 50) { | ||
return Promise.reject('Max results must be between 1 and 50 for search queries'); | ||
} | ||
const data = { | ||
q: encodeURIComponent(searchTerm), | ||
fields: encodeURIComponent(fields || | ||
'prevPageToken,nextPageToken,items(kind,id,snippet(title,description,thumbnails,publishedAt,channelId,channelTitle,liveBroadcastContent))'), | ||
maxResults, | ||
part: 'snippet', | ||
type, | ||
regionCode: youtube.region | ||
}; | ||
if (channelId) { | ||
data.channelId = channelId; | ||
} | ||
if (pageToken) { | ||
data.pageToken = pageToken; | ||
} | ||
if (category) { | ||
data.category = category; | ||
} | ||
if (eventType) { | ||
data.eventType = eventType; | ||
} | ||
if (onlyEmbeddable) { | ||
data.videoEmbeddable = 'true'; | ||
} | ||
if (videoType) { | ||
data.videoType = videoType; | ||
} | ||
const results = await youtube._request.api('search', data, youtube.token, youtube.accessToken); | ||
const items = []; | ||
results.items.forEach(item => { | ||
if (item.id.videoId) { | ||
items.push(new __1.Video(youtube, item)); | ||
} | ||
if (maxResults < 1 || maxResults > 50) { | ||
return Promise.reject('Max results must be greater than 0 and less than or equal to 50'); | ||
else if (item.id.channelId) { | ||
items.push(new __1.Channel(youtube, item)); | ||
} | ||
const data = { | ||
q: encodeURIComponent(searchTerm), | ||
fields: encodeURIComponent(fields || | ||
'prevPageToken,nextPageToken,items(kind,id,snippet(title,description,thumbnails,publishedAt,channelId,channelTitle,liveBroadcastContent))'), | ||
maxResults, | ||
part: 'snippet', | ||
type, | ||
regionCode: youtube.region | ||
}; | ||
if (channelId) { | ||
data.channelId = channelId; | ||
else if (item.id.playlistId) { | ||
items.push(new __1.Playlist(youtube, item)); | ||
} | ||
if (pageToken) { | ||
data.pageToken = pageToken; | ||
} | ||
if (category) { | ||
data.category = category; | ||
} | ||
if (eventType) { | ||
data.eventType = eventType; | ||
} | ||
if (onlyEmbeddable) { | ||
data.videoEmbeddable = 'true'; | ||
} | ||
if (videoType) { | ||
data.videoType = videoType; | ||
} | ||
const results = yield youtube._request.api('search', data, youtube.token, youtube.accessToken); | ||
const items = []; | ||
results.items.forEach(item => { | ||
if (item.id.videoId) { | ||
items.push(new __1.Video(youtube, item)); | ||
} | ||
else if (item.id.channelId) { | ||
items.push(new __1.Channel(youtube, item)); | ||
} | ||
else if (item.id.playlistId) { | ||
items.push(new __1.Playlist(youtube, item)); | ||
} | ||
}); | ||
const toReturn = { results: items, prevPageToken: results.prevPageToken, nextPageToken: results.nextPageToken }; | ||
if (youtube._shouldCache && youtube._cacheSearches) { | ||
youtube._cache(`search://${type}/"${searchTerm}"/${maxResults}/"${pageToken}"`, toReturn); | ||
} | ||
return toReturn; | ||
}); | ||
const toReturn = { results: items, prevPageToken: results.prevPageToken, nextPageToken: results.nextPageToken }; | ||
if (youtube._shouldCache && youtube._cacheSearches) { | ||
youtube._cache(`search://${type}/"${searchTerm}"/${maxResults}/"${pageToken}"`, toReturn); | ||
} | ||
return toReturn; | ||
} | ||
@@ -78,0 +68,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,24 +11,22 @@ exports.SubscriptionService = void 0; | ||
/* istanbul ignore next */ | ||
static getSubscriptionByChannels(youtube, subscriberId, channelId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const cached = util_1.Cache.get(`sub_by_channels://"${subscriberId}"/"${channelId}"`); | ||
if (youtube._shouldCache && cached) { | ||
return cached; | ||
} | ||
const data = { | ||
part: 'snippet,contentDetails,subscriberSnippet', | ||
forChannelId: channelId, | ||
channelId: subscriberId, | ||
maxResults: 1 | ||
}; | ||
const results = yield youtube._request.api('subscriptions', data, youtube.token, youtube.accessToken); | ||
if (results.items.length === 0) { | ||
return Promise.reject('Subscription not found'); | ||
} | ||
const toReturn = new __1.Subscription(youtube, results.items[0]); | ||
if (youtube._shouldCache && youtube._cacheSearches) { | ||
youtube._cache(`sub_by_channels://"${subscriberId}"/"${channelId}"`, toReturn); | ||
} | ||
return toReturn; | ||
}); | ||
static async getSubscriptionByChannels(youtube, subscriberId, channelId, parts) { | ||
const cached = util_1.Cache.get(`sub_by_channels://"${subscriberId}"/"${channelId}"`); | ||
if (youtube._shouldCache && cached) { | ||
return cached; | ||
} | ||
const data = { | ||
part: parts ? parts.join(',') : 'snippet,contentDetails,subscriberSnippet', | ||
forChannelId: channelId, | ||
channelId: subscriberId, | ||
maxResults: 1 | ||
}; | ||
const results = await youtube._request.api('subscriptions', data, youtube.token, youtube.accessToken); | ||
if (results.items.length === 0) { | ||
return Promise.reject('Subscription not found'); | ||
} | ||
const toReturn = new __1.Subscription(youtube, results.items[0]); | ||
if (youtube._shouldCache && youtube._cacheSearches) { | ||
youtube._cache(`sub_by_channels://"${subscriberId}"/"${channelId}"`, toReturn); | ||
} | ||
return toReturn; | ||
} | ||
@@ -44,0 +33,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PaginatedItemType = void 0; | ||
/** | ||
* @ignore | ||
*/ | ||
var PaginatedItemType; | ||
(function (PaginatedItemType) { | ||
PaginatedItemType[PaginatedItemType["VideoCategories"] = 0] = "VideoCategories"; | ||
PaginatedItemType[PaginatedItemType["VideoAbuseReportReasons"] = 1] = "VideoAbuseReportReasons"; | ||
PaginatedItemType[PaginatedItemType["Languages"] = 2] = "Languages"; | ||
PaginatedItemType[PaginatedItemType["Regions"] = 3] = "Regions"; | ||
PaginatedItemType[PaginatedItemType["PlaylistItems"] = 4] = "PlaylistItems"; | ||
PaginatedItemType[PaginatedItemType["VideoComments"] = 5] = "VideoComments"; | ||
PaginatedItemType[PaginatedItemType["ChannelComments"] = 6] = "ChannelComments"; | ||
PaginatedItemType[PaginatedItemType["CommentReplies"] = 7] = "CommentReplies"; | ||
PaginatedItemType[PaginatedItemType["Captions"] = 8] = "Captions"; | ||
PaginatedItemType[PaginatedItemType["Playlists"] = 9] = "Playlists"; | ||
PaginatedItemType[PaginatedItemType["Subscriptions"] = 10] = "Subscriptions"; | ||
PaginatedItemType[PaginatedItemType["ChannelSections"] = 11] = "ChannelSections"; | ||
})(PaginatedItemType || (exports.PaginatedItemType = PaginatedItemType = {})); | ||
//# sourceMappingURL=GetPaginatedItems.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -21,3 +25,4 @@ if (k2 === undefined) k2 = k; | ||
__exportStar(require("./ChannelSectionType"), exports); | ||
__exportStar(require("./Parts"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -8,2 +8,3 @@ "use strict"; | ||
class Cache { | ||
static cache = {}; | ||
static set(name, value, ttl) { | ||
@@ -41,4 +42,3 @@ this.cache[name] = { v: value, t: ttl }; | ||
exports.Cache = Cache; | ||
Cache.cache = {}; | ||
//# sourceMappingURL=caching.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -13,3 +13,3 @@ "use strict"; | ||
(url.startsWith('https://') ? `${url.substring(0, 8)}www.${url.substring(8)}` : `https://www.${url}`)); | ||
const parsed = url_1.parse(url, true); | ||
const parsed = (0, url_1.parse)(url, true); | ||
switch (parsed.hostname) { | ||
@@ -16,0 +16,0 @@ case 'www.youtube.com': |
@@ -11,2 +11,3 @@ "use strict"; | ||
class Request { | ||
baseUrl; | ||
constructor(baseUrl) { | ||
@@ -100,7 +101,7 @@ this.baseUrl = baseUrl; | ||
parseUrlToOptions(url, type, contentType) { | ||
const parsed = url_1.parse(url); | ||
const parsed = new url_1.URL(url); | ||
return { | ||
hostname: parsed.hostname, | ||
port: parsed.port ? parsed.port : 443, | ||
path: parsed.path, | ||
path: parsed.pathname + parsed.search, | ||
method: type, | ||
@@ -129,5 +130,2 @@ headers: { | ||
res.on('end', () => { | ||
if (res.statusCode === 404) { | ||
return reject(new Error('Not found')); | ||
} | ||
// no content | ||
@@ -140,3 +138,3 @@ if (res.statusCode === 204) { | ||
} | ||
if (!res.headers['content-type'].startsWith('application/json')) { | ||
if (res.statusCode !== 404 && !res.headers['content-type'].startsWith('application/json')) { | ||
return reject('Unexpected content type: ' + res.headers['content-type'] + '\nData: ' + data); | ||
@@ -149,3 +147,3 @@ } | ||
catch (err) { | ||
return reject('Error parsing JSON response: ' + data); | ||
return reject(new Error(res.statusCode === 404 ? 'Not found' : 'Error parsing JSON response: ' + data)); | ||
} | ||
@@ -155,2 +153,5 @@ if (parsed.error) { | ||
} | ||
else if (res.statusCode === 404) { | ||
return reject('Not found'); | ||
} | ||
return resolve(parsed); | ||
@@ -162,3 +163,3 @@ }); | ||
}; | ||
reqFunction(https_1.request(options, cb)); | ||
reqFunction((0, https_1.request)(options, cb)); | ||
}); | ||
@@ -165,0 +166,0 @@ } |
{ | ||
"name": "popyt", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "A very easy to use promise-based Youtube Data v3 API.", | ||
"homepage": "https://bbothell.rocks/popyt", | ||
"homepage": "https://bbothell.rocks/popyt/docs", | ||
"main": "out/index.js", | ||
@@ -10,7 +10,13 @@ "types": "typings/index.d.ts", | ||
"test": "mocha --exit --require ts-node/register/transpile-only --require source-map-support/register --parallel --recursive \"./test/!(oauth).spec.ts\" --timeout 10000", | ||
"coverage": "tsc && cross-env NODE_ENV=test nyc yarn test && cross-env NODE_ENV=test nyc report --reporter=text-lcov | coveralls", | ||
"docs": "gulp typedoc", | ||
"prepublishOnly": "gulp", | ||
"coverage": "tsc && cross-env NODE_ENV=test nyc --reporter=json yarn test", | ||
"docs:build": "yarn workspace docusaurus build", | ||
"docs:publish": "yarn workspace docusaurus deploy", | ||
"lint": "eslint src/**/*.ts test/**/*.ts" | ||
}, | ||
"nyc": { | ||
"include": "src" | ||
}, | ||
"workspaces": [ | ||
"docusaurus" | ||
], | ||
"author": "jasonhaxstuff", | ||
@@ -30,34 +36,35 @@ "license": "Unlicense", | ||
"devDependencies": { | ||
"@istanbuljs/nyc-config-typescript": "1.0.1", | ||
"@types/chai": "4.2.15", | ||
"@types/gulp": "4.0.7", | ||
"@types/gulp-sourcemaps": "0.0.34", | ||
"@types/merge2": "1.3.0", | ||
"@types/mocha": "8.2.1", | ||
"@types/node": "13.13.45", | ||
"@typescript-eslint/eslint-plugin": "4.16.1", | ||
"@typescript-eslint/parser": "4.16.1", | ||
"chai": "4.3.1", | ||
"coveralls": "3.1.0", | ||
"@istanbuljs/nyc-config-typescript": "1.0.2", | ||
"@types/chai": "4.3.5", | ||
"@types/gulp": "4.0.11", | ||
"@types/gulp-sourcemaps": "0.0.36", | ||
"@types/merge2": "1.4.1", | ||
"@types/mocha": "10.0.1", | ||
"@types/node": "20.3.1", | ||
"@typescript-eslint/eslint-plugin": "5.59.11", | ||
"@typescript-eslint/parser": "5.59.11", | ||
"chai": "4.3.7", | ||
"cross-env": "7.0.3", | ||
"dotenv": "8.2.0", | ||
"eslint": "7.21.0", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-jsdoc": "32.2.0", | ||
"docusaurus-plugin-typedoc": "^0.19.2", | ||
"dotenv": "16.3.1", | ||
"eslint": "8.43.0", | ||
"eslint-plugin-import": "2.27.5", | ||
"eslint-plugin-jsdoc": "46.2.6", | ||
"fs-nextra": "0.5.1", | ||
"gulp": "4.0.2", | ||
"gulp-sourcemaps": "3.0.0", | ||
"gulp-typedoc": "2.2.9", | ||
"gulp-typescript": "5.0.1", | ||
"gulp-typescript": "6.0.0-alpha.1", | ||
"merge2": "1.4.1", | ||
"mocha": "8.3.0", | ||
"mocha": "10.2.0", | ||
"nyc": "15.1.0", | ||
"source-map-support": "0.5.19", | ||
"ts-node": "9.1.1", | ||
"typedoc": "0.19.2", | ||
"typescript": "4.2.2" | ||
"source-map-support": "0.5.21", | ||
"ts-node": "10.9.1", | ||
"typedoc": "0.24.8", | ||
"typedoc-plugin-markdown": "^3.15.3", | ||
"typescript": "5.1.3" | ||
}, | ||
"repository": { | ||
"url": "https://github.com/jasonhaxstuff/popyt.git" | ||
} | ||
} | ||
}, | ||
"packageManager": "yarn@3.6.0" | ||
} |
@@ -7,3 +7,3 @@ # popyt | ||
[![GitHub license](https://img.shields.io/github/license/jasonhaxstuff/popyt.svg)](https://github.com/jasonhaxstuff/popyt/blob/master/LICENSE) | ||
[![Coverage status](https://coveralls.io/repos/github/jasonhaxstuff/popyt/badge.svg?branch=master)](https://coveralls.io/github/jasonhaxstuff/popyt?branch=master) | ||
[![Coverage status](https://codecov.io/gh/brandonbothell/popyt/branch/master/graph/badge.svg?token=OAV13MIW6S)](https://codecov.io/gh/brandonbothell/popyt) | ||
[![Actions status](https://github.com/jasonhaxstuff/popyt/workflows/Test/badge.svg)](https://github.com/jasonhaxstuff/popyt/actions) | ||
@@ -15,3 +15,3 @@ [![DeepScan grade](https://deepscan.io/api/teams/13038/projects/16072/branches/335663/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=13038&pid=16072&bid=335663) | ||
# Examples | ||
## See [the documentation](https://bbothell.rocks/popyt/docs). | ||
## See the [main class documentation](https://brandonbothell.github.io/popyt/docs/api/classes/Library_Exports.YouTube). | ||
Here are some basic methods: | ||
@@ -30,3 +30,3 @@ | ||
const { YouTube } = require('popyt') | ||
const youtube = new YouTube(apiKey, { cache: false }) | ||
const youtube = new YouTube(apiKey, undefined, { cache: false }) | ||
``` | ||
@@ -33,0 +33,0 @@ |
@@ -109,6 +109,4 @@ import { ChannelBrandingSettings, ChannelSectionType } from '.'; | ||
type: ChannelSectionType; | ||
style: 'horizontalRow' | 'verticalList'; | ||
title?: string; | ||
position?: number; | ||
defaultLanguage?: string; | ||
}; | ||
@@ -119,12 +117,2 @@ contentDetails?: { | ||
}; | ||
localizations?: { | ||
[key: string]: { | ||
title: string; | ||
}; | ||
}; | ||
targeting?: { | ||
countries?: string[]; | ||
languages?: string[]; | ||
regions?: string[]; | ||
}; | ||
}; | ||
@@ -131,0 +119,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" resolution-mode="require"/> | ||
import YouTube from '..'; | ||
@@ -84,6 +84,6 @@ /** | ||
/** | ||
* If [[Caption#status]] is `failed`, then this is populated with the reason failure. | ||
* If [[Caption.status]] is `failed`, then this is populated with the reason failure. | ||
*/ | ||
failureReason?: 'processingFailed' | 'unknownFormat' | 'unsupportedFormat'; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -90,0 +90,0 @@ * @ignore |
import { YouTube, Playlist, Channel, ChannelSectionType } from '..'; | ||
import { ChannelParts, ChannelSectionParts, PlaylistParts } from '../types/Parts'; | ||
/** | ||
* A YouTube channel section. | ||
* A YouTube [[Channel]] section. | ||
*/ | ||
@@ -39,6 +40,2 @@ export declare class ChannelSection { | ||
/** | ||
* The style of this channel section. | ||
*/ | ||
style: 'horizontalRow' | 'verticalList'; | ||
/** | ||
* The ID of the channel that created this channel section. | ||
@@ -52,10 +49,2 @@ */ | ||
/** | ||
* The language of the title of this channel section. | ||
*/ | ||
language: string; | ||
/** | ||
* The localized name of this channel section if the `hl` parameter was used when fetching it. | ||
*/ | ||
localizedName: string; | ||
/** | ||
* The IDs of the playlists in this channel section. Undefined if there aren't any. | ||
@@ -69,38 +58,7 @@ */ | ||
/** | ||
* The localizations of the channel section. | ||
* The playlists in the channel section. Only available after calling [[ChannelSection.fetchPlaylists]]. | ||
*/ | ||
localizations?: { | ||
/** | ||
* The language of the localized title. A [BCP-47](http://www.rfc-editor.org/rfc/bcp/bcp47.txt) language code. | ||
*/ | ||
[key: string]: { | ||
/** | ||
* The localized title. | ||
*/ | ||
title: string; | ||
}; | ||
}; | ||
/** | ||
* The targeting settings of the channel section. | ||
*/ | ||
targeting?: { | ||
/** | ||
* The languages for which the channel section is visible. | ||
*/ | ||
languages: string[]; | ||
/** | ||
* The regions where the channel section is visible. | ||
*/ | ||
regions: string[]; | ||
/** | ||
* The countries where the channel section is visible. | ||
*/ | ||
countries: string[]; | ||
}; | ||
/** | ||
* The playlists in the channel section. Only available after calling [[ChannelSection#fetchPlaylists]]. | ||
*/ | ||
playlists?: Playlist[]; | ||
/** | ||
* The channels in the channel section. Only available after calling [[ChannelSection#fetchChannels]]. | ||
* The channels in the channel section. Only available after calling [[ChannelSection.fetchChannels]]. | ||
*/ | ||
@@ -112,3 +70,3 @@ channels?: Channel[]; | ||
id: string; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -122,11 +80,11 @@ * @ignore | ||
*/ | ||
fetch(): Promise<this & ChannelSection>; | ||
fetch(parts?: ChannelSectionParts): Promise<this & ChannelSection>; | ||
/** | ||
* Fetches the channel section's playlists and assigns them to the [[ChannelSection#playlists]] property. | ||
* Fetches the channel section's playlists and assigns them to the [[ChannelSection.playlists]] property. | ||
*/ | ||
fetchPlaylists(): Promise<Playlist[]>; | ||
fetchPlaylists(parts?: PlaylistParts): Promise<Playlist[]>; | ||
/** | ||
* Fetches the channel section's playlists and assigns them to the [[ChannelSection#playlists]] property. | ||
* Fetches the channel section's channels and assigns them to the [[ChannelSection.channels]] property. | ||
*/ | ||
fetchChannels(): Promise<Channel[]>; | ||
fetchChannels(parts?: ChannelParts): Promise<Channel[]>; | ||
} |
@@ -1,3 +0,4 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { YouTube, Playlist, Thumbnail, YTComment, Subscription, ChannelSection, ChannelBrandingSettings } from '..'; | ||
import { ChannelParts, ChannelSectionParts, CommentThreadParts, PlaylistParts, SubscriptionParts } from '../types/Parts'; | ||
/** | ||
@@ -82,3 +83,3 @@ * A YouTube channel. | ||
/** | ||
* The channel's uploads. Only available after calling `Channel#fetchVideos()` | ||
* The channel's uploads. Only available after calling [[Channel.fetchVideos]] | ||
*/ | ||
@@ -96,3 +97,3 @@ videos: Playlist; | ||
/** | ||
* The channel's comments. Only defined when `Channel#fetchComments` is called. | ||
* The channel's comments. Only defined when [[Channel.fetchComments]] is called. | ||
*/ | ||
@@ -105,11 +106,11 @@ comments: YTComment[]; | ||
/** | ||
* The channel's playlists. Only defined when `Channel#fetchPlaylists` is called. | ||
* The channel's playlists. Only defined when [[Channel.fetchPlaylists]] is called. | ||
*/ | ||
playlists: Playlist[]; | ||
/** | ||
* The channel's subscriptions. Only defined when `Channel#fetchSubscriptions` is called. | ||
* The channel's subscriptions. Only defined when [[Channel.fetchSubscriptions]] is called. | ||
*/ | ||
subscriptions: Subscription[]; | ||
/** | ||
* The channel's sections. Only defined when [[Channel#fetchSections]] is called. | ||
* The channel's sections. Only defined when [[Channel.fetchSections]] is called. | ||
*/ | ||
@@ -138,3 +139,3 @@ sections: ChannelSection[]; | ||
}; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -154,26 +155,27 @@ * @ignore | ||
*/ | ||
fetch(): Promise<this & Channel>; | ||
fetch(parts?: ChannelParts): Promise<this & Channel>; | ||
/** | ||
* Fetches the channel's videos and assigns them to the `Channel#videos` property. | ||
* Fetches the channel's playlist of uploads and assigns it to the [[Channel.videos]] property. | ||
*/ | ||
fetchVideos(): Promise<Playlist>; | ||
fetchVideos(parts?: PlaylistParts): Promise<Playlist>; | ||
/** | ||
* Fetches the channel's discussion tab comments and assigns them to Channel#comments. | ||
* @param maxResults The maximum amount of comments to fetch | ||
* @deprecated See https://support.google.com/youtube/thread/130882091?hl=en&msgid=131295194 | ||
* Fetches the channel's discussion tab comments and assigns them to [[Channel.comments]]. | ||
* @param pages The number of pages of comments to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchComments(maxResults?: number): Promise<YTComment[]>; | ||
fetchComments(pages?: number, parts?: CommentThreadParts): Promise<YTComment[]>; | ||
/** | ||
* Fetches the channel's playlists and assigns them to Channel#playlists. | ||
* @param maxResults The maximum amount of playlists to fetch | ||
* Fetches the channel's playlists and assigns them to [[Channel.playlists]]. | ||
* @param pages The number of pages of playlists to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchPlaylists(maxResults?: number): Promise<Playlist[]>; | ||
fetchPlaylists(pages?: number, parts?: PlaylistParts): Promise<Playlist[]>; | ||
/** | ||
* Fetches the channel's subscriptions and assigns them to Channel#subscriptions. | ||
* @param maxResults The maximum amount of subscriptions to fetch | ||
* Fetches the channel's subscriptions and assigns them to [[Channel.subscriptions]]. | ||
* @param pages The number of pages of subscriptions to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchSubscriptions(maxResults?: number): Promise<Subscription[]>; | ||
fetchSubscriptions(pages?: number, parts?: SubscriptionParts): Promise<Subscription[]>; | ||
/** | ||
* Fetches the channel's sections and assigns them to [[Channel#sections]]. | ||
* Fetches the channel's sections and assigns them to [[Channel.sections]]. | ||
*/ | ||
fetchSections(): Promise<ChannelSection[]>; | ||
fetchSections(parts?: ChannelSectionParts): Promise<ChannelSection[]>; | ||
/** | ||
@@ -180,0 +182,0 @@ * Subscribes to the channel. |
import { YouTube } from '..'; | ||
import { CommentParts } from '../types/Parts'; | ||
export declare class YTComment { | ||
@@ -91,15 +92,20 @@ /** | ||
/** | ||
* Either the ID of the video that it is commenting on, the ID of the | ||
* comment it is replying to, or the ID of the channel it is commenting | ||
* on. | ||
* Undefined whenever the comment is fetched directly using the ID. | ||
* The ID of the channel that uploaded the video this comment is on, if any. | ||
*/ | ||
parentId: string; | ||
channelId?: string; | ||
/** | ||
* The ID of the video that this comment is on, if any. | ||
*/ | ||
videoId?: string; | ||
/** | ||
* If this comment is a reply, then this is the ID of the comment it is replying to. | ||
*/ | ||
parentCommentId?: string; | ||
/** | ||
* Replies directed to the comment. If the comment was fetched from a video, | ||
* then this will be partially filled. You'll need to use Comment#fetchReplies | ||
* then this will be partially filled. You'll need to use [[Comment.fetchReplies]] | ||
* to get all of the replies, though. | ||
*/ | ||
replies: YTComment[]; | ||
constructor(youtube: YouTube, data: any, type: 'video' | 'channel'); | ||
constructor(youtube: YouTube, data: any, full?: boolean, replies?: any[]); | ||
/** | ||
@@ -111,5 +117,5 @@ * @ignore | ||
* Fetches replies to the comment. | ||
* @param maxResults The maximum amount of replies to fetch. Fetches all comments if <=0. | ||
* @param pages The number of pages of comments to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchReplies(maxResults?: number): Promise<YTComment[]>; | ||
fetchReplies(pages?: number, parts?: CommentParts): Promise<YTComment[]>; | ||
/** | ||
@@ -116,0 +122,0 @@ * Edits the comment. |
@@ -0,1 +1,5 @@ | ||
/** | ||
* @packageDocumentation | ||
* @module Entities | ||
*/ | ||
export * from './video'; | ||
@@ -2,0 +6,0 @@ export * from './channel'; |
@@ -42,3 +42,3 @@ import YouTube from '..'; | ||
name: string; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -45,0 +45,0 @@ * @ignore |
import { YouTube, Video, Thumbnail } from '..'; | ||
import { PlaylistItemParts, PlaylistParts } from '../types/Parts'; | ||
/** | ||
@@ -43,3 +44,3 @@ * A YouTube playlist. | ||
/** | ||
* The videos in the playlist. Only available after calling `Playlist#fetchVideos()`. | ||
* The videos in the playlist. Only available after calling [[Playlist.fetchVideos]]. | ||
*/ | ||
@@ -81,3 +82,3 @@ videos: Video[]; | ||
tags: string[]; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -89,5 +90,5 @@ * @ignore | ||
* Adds videos in this playlist to the `videos` property of this playlist. | ||
* @param maxResults Fetches all videos if <=0. | ||
* @param pages The number of pages of videos to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchVideos(maxResults?: number): Promise<Video[]>; | ||
fetchVideos(pages?: number, parts?: PlaylistItemParts): Promise<Video[]>; | ||
/** | ||
@@ -97,3 +98,3 @@ * Fetches this playlist and reassigns this object to the new playlist object. | ||
*/ | ||
fetch(): Promise<this & Playlist>; | ||
fetch(parts?: PlaylistParts): Promise<this & Playlist>; | ||
/** | ||
@@ -137,7 +138,12 @@ * Edits the playlist. | ||
* Must be using an access token with correct scopes. | ||
* @param videoResolvable The URL, ID, or Title of the video. Must specify this or `itemId`. | ||
* @param itemId The playlist item ID if you have it. Must specify this or `videoResolvable`. | ||
* @param videoResolvable The URL, ID, or Title of the video. | ||
*/ | ||
removeVideo(videoResolvable?: string, itemId?: string): Promise<never>; | ||
removeVideo(videoResolvable: string): Promise<void>; | ||
/** | ||
* Removes a [[Video]] from the playlist. | ||
* Must be using an access token with correct scopes. | ||
* @param playlistItemId The playlist item ID (not the same as video id. See [[Playlist.removeVideo]]). | ||
*/ | ||
removeItem(playlistItemId: string): Promise<void>; | ||
/** | ||
* Deletes the playlist. | ||
@@ -144,0 +150,0 @@ * Must be using an access token with correct scopes. |
@@ -42,3 +42,3 @@ import YouTube from '..'; | ||
name: string; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -45,0 +45,0 @@ * @ignore |
import YouTube from '..'; | ||
import { Thumbnail } from '../types'; | ||
import { SubscriptionParts } from '../types/Parts'; | ||
/** | ||
@@ -25,3 +26,2 @@ * A YouTube subscription. | ||
* Whether or not this is a full subscription object. | ||
* **CURRENTLY NOT WORKING**, see https://issuetracker.google.com/issues/181152600 | ||
*/ | ||
@@ -115,3 +115,3 @@ full: boolean; | ||
activities: 'all' | 'uploads'; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -126,3 +126,3 @@ * @ignore | ||
*/ | ||
fetch(): Promise<this & (string | Subscription)>; | ||
fetch(parts?: SubscriptionParts): Promise<this & Subscription>; | ||
} |
@@ -45,3 +45,3 @@ import YouTube from '..'; | ||
}[]; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -48,0 +48,0 @@ * @ignore |
@@ -46,3 +46,3 @@ import YouTube from '..'; | ||
assignable: boolean; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -49,0 +49,0 @@ * @ignore |
@@ -1,5 +0,6 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { YouTube, VideoUpdateResource, Caption } from '..'; | ||
import { Thumbnail, ISODuration } from '../types'; | ||
import { YTComment } from './comment'; | ||
import { CommentThreadParts, VideoParts } from '../types/Parts'; | ||
/** | ||
@@ -30,3 +31,3 @@ * A YouTube video. | ||
/** | ||
* Whether or not this is a full video object. | ||
* Whether or not this is a full video object (would it be the same if we ran [[Video.fetch]] under the same conditions as last time?). | ||
*/ | ||
@@ -112,3 +113,3 @@ full: boolean; | ||
/** | ||
* The video's comments. Only defined when Video#fetchComments is called. | ||
* The video's comments. Only defined when [[Video.fetchComments]] is called. | ||
*/ | ||
@@ -144,6 +145,6 @@ comments: YTComment[]; | ||
/** | ||
* The caption data associated with this video. Only available after running [[Video#fetchCaptions]]. | ||
* The caption data associated with this video. Only available after running [[Video.fetchCaptions]]. | ||
*/ | ||
captions: Caption[]; | ||
constructor(youtube: YouTube, data: any); | ||
constructor(youtube: YouTube, data: any, full?: boolean); | ||
/** | ||
@@ -163,10 +164,11 @@ * @ignore | ||
*/ | ||
fetch(): Promise<this & Video>; | ||
fetch(parts?: VideoParts): Promise<this & Video>; | ||
/** | ||
* Fetches the video's comments and assigns them to Video#comments. | ||
* @param maxResults The maximum amount of comments to fetch | ||
* Fetches the video's comments and assigns them to [[Video.comments]]. | ||
* @param pages The number of pages of comments to fetch. Defaults to 1. Set <1 to fetch all items. | ||
*/ | ||
fetchComments(maxResults?: number): Promise<YTComment[]>; | ||
fetchComments(pages?: number, parts?: CommentThreadParts): Promise<YTComment[]>; | ||
/** | ||
* Gets the user's rating on the video. | ||
* Must be using an access token with correct scopes. | ||
*/ | ||
@@ -173,0 +175,0 @@ getRating(): Promise<'like' | 'dislike' | 'none' | 'unspecified'>; |
@@ -0,4 +1,9 @@ | ||
/** | ||
* @module Library Exports | ||
*/ | ||
import { Video, Channel, Playlist, YTComment, Subscription, VideoCategory, Language, Region, ChannelSection } from './entities'; | ||
import { Request } from './util'; | ||
import { OAuth } from './oauth'; | ||
import { VideoParts, ChannelParts, ChannelSectionParts, CommentParts, CommentThreadParts, PlaylistItemParts, PlaylistParts, SubscriptionParts } from './types/Parts'; | ||
import { PageOptions } from './types'; | ||
export * from './entities'; | ||
@@ -37,7 +42,7 @@ export * from './types'; | ||
/** | ||
* The language for the API to respond in. See [[YouTube#getLanguages]]. | ||
* The language for the API to respond in. See [[YouTube.getLanguages]]. | ||
*/ | ||
language: string; | ||
/** | ||
* The region for the API cater responses to. See [[YouTube#getRegions]]. | ||
* The region for the API cater responses to. See [[YouTube.getRegions]]. | ||
*/ | ||
@@ -49,6 +54,6 @@ region: string; | ||
* It could be an API key or an OAuth 2.0 token. | ||
* @param accessToken A Google OAuth 2.0 access token. Used for [[YouTube#oauth]] methods. | ||
* @param accessToken A Google OAuth 2.0 access token. Used for [[YouTube.oauth]] methods. | ||
* @param options Caching options. Recommended to change. | ||
* @param language The language for the API to respond in. See [[YouTube#getLanguages]]. | ||
* @param region The region for the API cater responses to. See [[YouTube#getRegions]]. | ||
* @param language The language for the API to respond in. See [[YouTube.getLanguages]]. | ||
* @param region The region for the API cater responses to. See [[YouTube.getRegions]]. | ||
*/ | ||
@@ -64,3 +69,3 @@ constructor(token?: string, accessToken?: string, options?: YouTubeOptions, language?: string, region?: string); | ||
* @param searchTerm What to search for on YouTube. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. Max 50. | ||
* @param fields The fields to include in the response. Includes all by default. | ||
@@ -70,5 +75,2 @@ * @param pageToken The page token to start at. Provide this if you have received it as output from a call to a search method. | ||
search(types: (typeof Video | typeof Channel | typeof Playlist)[], searchTerm: string, maxResults?: number, pageToken?: string, fields?: string): Promise<{ | ||
/** | ||
* @ignore | ||
*/ | ||
results: (Video | Channel | Playlist)[]; | ||
@@ -81,3 +83,3 @@ prevPageToken: string; | ||
* @param searchTerm What to search for on YouTube. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. Max 50. | ||
* @param pageToken The page token to start at. Provide this if you have received it as output from a call to a search method. | ||
@@ -97,3 +99,3 @@ * @param channelId The channel ID that you want to specifically search for. | ||
* @param searchTerm What to search for on YouTube. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. Max 50. | ||
* @param pageToken The page token to start at. Provide this if you have received it as output from a call to a search method. | ||
@@ -109,3 +111,3 @@ */ | ||
* @param searchTerm What to search for on YouTube. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. | ||
* @param maxResults The maximum amount of results to find. Defaults to 10. Max 50. | ||
* @param pageToken The page token to start at. Provide this if you have received it as output from a call to a search method. | ||
@@ -122,4 +124,5 @@ */ | ||
* @param videoResolvable The URL, ID, or Title of the video. | ||
* @param parts The parts of the video to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getVideo(videoResolvable: string | Video): Promise<Video>; | ||
getVideo(videoResolvable: string | Video, parts?: VideoParts): Promise<Video>; | ||
/** | ||
@@ -130,4 +133,5 @@ * Get a [[Channel]] object from the Username, URL or ID of a channel. | ||
* @param channelResolvable The Username, URL or ID of the channel. | ||
* @param parts The parts of the channel to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getChannel(channelResolvable: string | Channel): Promise<Channel>; | ||
getChannel(channelResolvable: string | Channel, parts?: ChannelParts): Promise<Channel>; | ||
/** | ||
@@ -137,14 +141,17 @@ * Get a [[Playlist]] object from the URL, ID, or Title of a playlist. | ||
* @param playlistResolvable The URL, ID, or Title of the playlist. | ||
* @param parts The parts of the playlist to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getPlaylist(playlistResolvable: string | Playlist): Promise<Playlist>; | ||
getPlaylist(playlistResolvable: string | Playlist, parts?: PlaylistParts): Promise<Playlist>; | ||
/** | ||
* Get a [[Comment]] object from the ID of a comment. | ||
* @param commentId The ID of the comment. | ||
* @param parts The parts of the comment to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getComment(commentId: string): Promise<YTComment>; | ||
getComment(commentId: string, parts?: CommentParts): Promise<YTComment>; | ||
/** | ||
* Get a [[Subscription]] object from the ID of a subscription. | ||
* @param subscriptionId The ID of the subscription. | ||
* @param parts The parts of the subscription to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getSubscription(subscriptionId: string): Promise<Subscription>; | ||
getSubscription(subscriptionId: string, parts?: SubscriptionParts): Promise<Subscription>; | ||
/** | ||
@@ -158,4 +165,5 @@ * Get a [[VideoCategory]] object from the ID of a category. | ||
* @param categoryId The ID of the section. | ||
* @param parts The parts of the channel section to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getChannelSection(sectionId: string): Promise<ChannelSection>; | ||
getChannelSection(sectionId: string, parts?: ChannelSectionParts): Promise<ChannelSection>; | ||
/** | ||
@@ -165,57 +173,78 @@ * Get a [[Subscription]] object from the subscriber and channel of a subscription. | ||
* @param channelResolvable A resolvable channel that is the channel being subscribed to. | ||
* @param parts The parts of the subscription to fetch (saves quota if you aren't using certain properties!) | ||
*/ | ||
getSubscriptionByChannels(subscriberResolvable: string | Channel, channelResolvable: string | Channel): Promise<Subscription>; | ||
getSubscriptionByChannels(subscriberResolvable: string | Channel, channelResolvable: string | Channel, parts?: SubscriptionParts): Promise<Subscription>; | ||
/** | ||
* Get `maxResults` videos in a [[Playlist]]. Used mostly internally with `Playlist#fetchVideos`. | ||
* Get `maxPerPage * pages` videos in a [[Playlist]]. Used mostly internally with [[Playlist.fetchVideos]]. | ||
* @param playlistResolvable The URL, ID, or Title of the playlist. | ||
* @param maxResults The maximum amount of videos to get from the playlist. If <=0, returns all videos in the playlist. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the videos to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial video objects. | ||
*/ | ||
getPlaylistItems(playlistResolvable: string | Playlist, maxResults?: number): Promise<Video[]>; | ||
getPlaylistItems(playlistResolvable: string | Playlist, pageOptions?: PageOptions, parts?: PlaylistItemParts): Promise<Video[]>; | ||
/** | ||
* Get `maxResults` [[YTComment]]s from a [[Video]]. Used mostly internally with `Video#fetchComments`. | ||
* Get `maxPerPage * pages` [[YTComment]]s from a [[Video]]. Used mostly internally with [[Video.fetchComments]]. | ||
* @param videoResolvable The URL, ID, or Title of the video. | ||
* @param maxResults The maximum amount of comments to get from the video. If <=0, returns all comments on the video. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the comments to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial comment objects. | ||
*/ | ||
getVideoComments(videoResolvable: string | Video, maxResults?: number): Promise<YTComment[]>; | ||
getVideoComments(videoResolvable: string | Video, pageOptions?: PageOptions, parts?: CommentThreadParts): Promise<YTComment[]>; | ||
/** | ||
* Get `maxResults` [[YTComment]]s from a [[Channel]]'s discussion tab. Used mostly internally with `Channel#fetchComments`. | ||
* @deprecated See https://support.google.com/youtube/thread/130882091?hl=en&msgid=131295194 | ||
* | ||
* Get `maxPerPage * pages` [[YTComment]]s from a [[Channel]]'s discussion tab. Used mostly internally with [[Channel.fetchComments]]. | ||
* @param channelResolvable The Username, URL, or ID of the channel. | ||
* @param maxResults The maximum amount of comments to get from the channel. If <=0, returns all comments on the channel. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the comments to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial comment objects. | ||
*/ | ||
getChannelComments(channelResolvable: string | Channel, maxResults?: number): Promise<YTComment[]>; | ||
getChannelComments(channelResolvable: string | Channel, pageOptions?: PageOptions, parts?: CommentThreadParts): Promise<YTComment[]>; | ||
/** | ||
* Get `maxResults` of a [[Channel]]'s [[Playlist]]s. Used mostly internally with `Channel#fetchPlaylists`. | ||
* Get `maxPerPage * pages` of a [[Channel]]'s [[Playlist]]s. Used mostly internally with [[Channel.fetchPlaylists]]. | ||
* @param channelResolvable The Username, URL, or ID of the channel. | ||
* @param maxResults The maximum amount of playlists to get from the channel. If <=0, returns all playlists. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the playlists to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial playlist objects. | ||
*/ | ||
getChannelPlaylists(channelResolvable: string | Channel, maxResults?: number): Promise<Playlist[]>; | ||
getChannelPlaylists(channelResolvable: string | Channel, pageOptions?: PageOptions, parts?: PlaylistParts): Promise<Playlist[]>; | ||
/** | ||
* Get `maxResults` of a [[Channel]]'s [[Subscription]]s. Used mostly internally with `Channel#fetchSubscriptions`. | ||
* Get `maxPerPage * pages` of a [[Channel]]'s [[Subscription]]s. Used mostly internally with [[Channel.fetchSubscriptions]]. | ||
* @param channelResolvable The Username, URL, or ID of the channel. | ||
* @param maxResults The maximum amount of subscriptions to get from the channel. If <=0, returns all subscriptions. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the subscriptions to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial subscription objects. | ||
*/ | ||
getChannelSubscriptions(channelResolvable: string | Channel, maxResults?: number): Promise<Subscription[]>; | ||
getChannelSubscriptions(channelResolvable: string | Channel, pageOptions?: PageOptions, parts?: SubscriptionParts): Promise<Subscription[]>; | ||
/** | ||
* Get `maxResults` replies to a [[YTComment]]. Used mostly internally with `Comment#fetchReplies`. | ||
* Get `maxPerPage * pages` replies to a [[YTComment]]. Used mostly internally with [[Comment.fetchReplies]]. | ||
* @param commentId The ID of the comment to get replies from. | ||
* @param maxResults The maximum amount of replies to get. Gets all replies if <=0. | ||
* @param pageOptions The number of pages and maximum number of items per page. | ||
* Fetches the maximum number of items allowed by the API per page by default. | ||
* Set pages to a value <=0 to fetch all. | ||
* @param parts The parts of the replies to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial comment objects. | ||
*/ | ||
getCommentReplies(commentId: string, maxResults?: number): Promise<YTComment[]>; | ||
getCommentReplies(commentId: string, pageOptions?: PageOptions, parts?: CommentParts): Promise<YTComment[]>; | ||
/** | ||
* Gets the [[ChannelSection]]s of a [[Channel]]. Used mostly internally with [[Channel#fetchSections]]. | ||
* Gets the [[ChannelSection]]s of a [[Channel]]. Used mostly internally with [[Channel.fetchSections]]. | ||
* @param channelResolvable The Username, URL, or ID of the channel to get the sections from. | ||
* @param parts The parts of the channel sections to fetch (saves quota if you aren't using certain properties!) | ||
* @returns Partial channel section objects. | ||
*/ | ||
getChannelSections(channelResolvable: string | Channel): Promise<ChannelSection[]>; | ||
getChannelSections(channelResolvable: string | Channel, parts?: ChannelSectionParts): Promise<ChannelSection[]>; | ||
/** | ||
* Get the list of categories in `this.region`. | ||
* @param all Whether or not to get all categories (otherwise just gets a page). | ||
*/ | ||
getCategories(all?: boolean): Promise<VideoCategory[]>; | ||
getCategories(): Promise<VideoCategory[]>; | ||
/** | ||
@@ -230,3 +259,3 @@ * Get a list of languages that YouTube supports. | ||
} | ||
declare type YouTubeOptions = { | ||
export type YouTubeOptions = { | ||
/** | ||
@@ -233,0 +262,0 @@ * Whether or not to cache entities. |
@@ -1,6 +0,10 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" resolution-mode="require"/> | ||
/** | ||
* @module OAuth | ||
*/ | ||
import YouTube, { YTComment, Channel, Playlist, Subscription, Video, VideoAbuseReportReason, ChannelSection, VideoUpdateResource, ChannelBrandingSettings, ChannelSectionType, Caption } from '.'; | ||
import { ChannelParts, PlaylistParts, SubscriptionParts } from './types/Parts'; | ||
/** | ||
* All methods requiring an OAuth access token. | ||
* Use `YouTube#oauth` to access these methods. | ||
* Use `YouTube.oauth` to access these methods. | ||
*/ | ||
@@ -22,17 +26,19 @@ export declare class OAuth { | ||
*/ | ||
getMe(): Promise<Channel>; | ||
getMe(parts?: ChannelParts): Promise<Channel>; | ||
/** | ||
* Gets the authorized user's [[Subscription]]s. | ||
* Last tested 05/18/2020 11:48. PASSING | ||
* @param maxResults The maximum number of subscriptions to fetch. | ||
* Fetches 10 by default. Set to a value <=0 to fetch all. | ||
* @param maxPerPage The maximum number of subscriptions to fetch per page. | ||
* Fetches the maximum allowed by the API by default. | ||
* Set to a value <=0 to fetch all. | ||
*/ | ||
getMySubscriptions(maxResults?: number): Promise<Subscription[]>; | ||
getMySubscriptions(maxPerPage?: number, parts?: SubscriptionParts): Promise<Subscription[]>; | ||
/** | ||
* Gets the authorized user's [[Playlist]]s. | ||
* Last tested 05/18/2020 11:48. PASSING | ||
* @param maxResults The maximum number of playlists to fetch. | ||
* Fetches 10 by default. Set to a value <=0 to fetch all. | ||
* @param maxPerPage The maximum number of playlists to fetch per page. | ||
* Fetches the maximum allowed by the API by default. | ||
* Set to a value <=0 to fetch all. | ||
*/ | ||
getMyPlaylists(maxResults?: number): Promise<Playlist[]>; | ||
getMyPlaylists(maxPerPage?: number, parts?: PlaylistParts): Promise<Playlist[]>; | ||
/** | ||
@@ -52,4 +58,3 @@ * Post a [[Comment]] on a [[Video]] or [[Channel]] discussion. | ||
* @param text The text to reply with. | ||
* @param commentType What this comment is on - defaults to video. | ||
* Required for [[YTComment#url]] to be correct. | ||
* Required for [[YTComment.url]] to be correct. | ||
*/ | ||
@@ -59,17 +64,8 @@ replyToComment(commentId: string, text: string): Promise<YTComment>; | ||
* Edit a [[Comment]] on a [[Video]] or [[Channel]] discussion. | ||
* Last tested 05/18/2020 11:48. PASSING | ||
* Last tested 07/05/2021 17:40. PASSING | ||
* @param commentId The ID of the comment. | ||
* @param text The new text content of the comment. | ||
* @param commentId The ID of the comment. | ||
*/ | ||
editComment(text: string, commentId: string): Promise<YTComment>; | ||
editComment(commentId: string, text: string): Promise<YTComment>; | ||
/** | ||
* Edits a [[YTComment]] reply. | ||
* Last tested 05/18/2020 11:48. PASSING | ||
* @param commentId The ID of the reply to edit. | ||
* @param text The text to edit the reply to. | ||
* @param commentType What this comment is on - defaults to video. | ||
* Required for [[YTComment#url]] to be correct. | ||
*/ | ||
editCommentReply(commentId: string, text: string): Promise<YTComment>; | ||
/** | ||
* Marks a [[YTComment]] as spam. | ||
@@ -278,3 +274,3 @@ * Last tested NEVER | ||
* @returns The URL of the uploaded banner, used as | ||
* [[BrandingSettings#image#bannerExternalUrl]] in [[OAuth#updateChannelBranding]] | ||
* [[BrandingSettings.image.bannerExternalUrl]] in [[OAuth.updateChannelBranding]] | ||
*/ | ||
@@ -289,20 +285,8 @@ uploadChannelBanner(image: { | ||
* @param type The type of channel section. | ||
* @param style The style of the channel section. | ||
* @param name The name of the channel section. | ||
* @param position The position of the channel section on the channel homepage. | ||
* @param language The default language of the channel section. | ||
* @param playlistsResolvable Any playlists in the channel section. | ||
* @param channelsResolvable Any channels in the channel section. | ||
* @param localizations Translations of the channel section's title. | ||
* @param targeting Targeting data for the channel section. | ||
*/ | ||
addChannelSection(type: ChannelSectionType, style: 'horizontalRow' | 'verticalList', name?: string, language?: string, playlistsResolvable?: (string | Playlist)[], channelsResolvable?: (string | Channel)[], localizations?: { | ||
[key: string]: { | ||
title: string; | ||
}; | ||
}, targeting?: { | ||
countries?: string[]; | ||
languages?: string[]; | ||
regions?: string[]; | ||
}): Promise<ChannelSection>; | ||
addChannelSection(type: ChannelSectionType, name?: string, position?: number, playlistsResolvable?: (string | Playlist)[], channelsResolvable?: (string | Channel)[]): Promise<ChannelSection>; | ||
/** | ||
@@ -324,11 +308,3 @@ * Updates a [[ChannelSection]]. | ||
*/ | ||
updateChannelSection(id: string, type: ChannelSectionType, style: 'horizontalRow' | 'verticalList', name?: string, position?: number, language?: string, playlistsResolvable?: (string | Playlist)[], channelsResolvable?: (string | Channel)[], localizations?: { | ||
[key: string]: { | ||
title: string; | ||
}; | ||
}, targeting?: { | ||
countries?: string[]; | ||
languages?: string[]; | ||
regions?: string[]; | ||
}): Promise<ChannelSection>; | ||
updateChannelSection(id: string, type: ChannelSectionType, name?: string, position?: number, playlistsResolvable?: (string | Playlist)[], channelsResolvable?: (string | Channel)[]): Promise<ChannelSection>; | ||
/** | ||
@@ -348,3 +324,3 @@ * Deletes a [[ChannelSection]]. | ||
/** | ||
* Gets the [[Caption]]s of a [[Video]]. Used mostly internally with [[Video#fetchCaptions]]. | ||
* Gets the [[Caption]]s of a [[Video]]. Used mostly internally with [[Video.fetchCaptions]]. | ||
* Last tested 06/11/2020 04:50. PASSING | ||
@@ -351,0 +327,0 @@ * @param videoResolvable The Title, URL, or ID of the video to get the captions from. |
import YouTube, { Video, Channel, Playlist } from '..'; | ||
import { ItemTypes, ItemReturns, PaginatedItemsEndpoints, PaginatedItemsReturns } from '../types'; | ||
import { ItemTypes, ItemReturns, PaginatedItemsReturns, PaginatedItemOptions } from '../types'; | ||
/** | ||
@@ -7,5 +7,13 @@ * @ignore | ||
export declare class GenericService { | ||
static getItem(youtube: YouTube, type: ItemTypes, mine: boolean, id?: string): Promise<ItemReturns>; | ||
static getPaginatedItems(youtube: YouTube, endpoint: PaginatedItemsEndpoints, mine: boolean, id?: string, maxResults?: number, subId?: string): Promise<PaginatedItemsReturns>; | ||
static getItem(youtube: YouTube, type: ItemTypes, mine: boolean, id?: string, parts?: string[]): Promise<ItemReturns>; | ||
/** | ||
* | ||
* @param maxPerPage Leave undefined or set to < 1 to fetch the maximum allowed by the API for any given type. | ||
* @param pages Number of pages to fetch from the API. Set to < 1 to fetch all of them. Defaults to 1. | ||
* @param pageToken The page to start at (retrieved from the return value of a previous call to this function) | ||
* | ||
* @returns An object containing the array of instantiated entities as well as possible next and previous page tokens. | ||
*/ | ||
static getPaginatedItems({ youtube, type, mine, id, maxPerPage, pages, pageToken, subId, parts }: PaginatedItemOptions): Promise<PaginatedItemsReturns>; | ||
static getId(youtube: YouTube, input: string | Video | Channel | Playlist, type: typeof Video | typeof Channel | typeof Playlist): Promise<string>; | ||
} |
import YouTube, { Subscription } from '..'; | ||
import { SubscriptionParts } from '../types/Parts'; | ||
/** | ||
@@ -6,3 +7,3 @@ * @ignore | ||
export declare class SubscriptionService { | ||
static getSubscriptionByChannels(youtube: YouTube, subscriberId: string, channelId: string): Promise<Subscription>; | ||
static getSubscriptionByChannels(youtube: YouTube, subscriberId: string, channelId: string, parts?: SubscriptionParts): Promise<Subscription>; | ||
} |
@@ -1,2 +0,2 @@ | ||
export declare type Banners = { | ||
export type Banners = { | ||
bannerImageUrl: string; | ||
@@ -3,0 +3,0 @@ bannerMobileImageUrl: string; |
@@ -1,2 +0,2 @@ | ||
export declare type ChannelBrandingSettings = { | ||
export type ChannelBrandingSettings = { | ||
channel?: { | ||
@@ -58,3 +58,3 @@ /** | ||
/** | ||
* The URL of a banner (obtained from [[OAuth#uploadChannelBanner]]) to use for the channel. | ||
* The URL of a banner (obtained from [[OAuth.uploadChannelBanner]]) to use for the channel. | ||
*/ | ||
@@ -61,0 +61,0 @@ bannerExternalUrl?: string; |
@@ -1,1 +0,1 @@ | ||
export declare type ChannelSectionType = 'allPlaylists' | 'completedEvents' | 'likedPlaylists' | 'likes' | 'liveEvents' | 'multipleChannels' | 'multiplePlaylists' | 'popularUploads' | 'postedPlaylists' | 'postedVideos' | 'recentActivity' | 'recentPosts' | 'recentUploads' | 'singlePlaylist' | 'subscriptions' | 'upcomingEvents'; | ||
export type ChannelSectionType = 'allPlaylists' | 'completedEvents' | 'likedPlaylists' | 'likes' | 'liveEvents' | 'multipleChannels' | 'multiplePlaylists' | 'popularUploads' | 'postedPlaylists' | 'postedVideos' | 'recentActivity' | 'recentPosts' | 'recentUploads' | 'singlePlaylist' | 'subscriptions' | 'upcomingEvents'; |
@@ -5,6 +5,6 @@ import { Video, Channel, Playlist, YTComment, Subscription, VideoCategory, ChannelSection, Caption } from '..'; | ||
*/ | ||
export declare type ItemTypes = typeof Video | typeof Channel | typeof Playlist | typeof YTComment | typeof Subscription | typeof VideoCategory | typeof ChannelSection | typeof Caption; | ||
export type ItemTypes = typeof Video | typeof Channel | typeof Playlist | typeof YTComment | typeof Subscription | typeof VideoCategory | typeof ChannelSection | typeof Caption; | ||
/** | ||
* @ignore | ||
*/ | ||
export declare type ItemReturns = Video | Channel | Playlist | YTComment | Subscription | VideoCategory | ChannelSection | Caption; | ||
export type ItemReturns = Video | Channel | Playlist | YTComment | Subscription | VideoCategory | ChannelSection | Caption; |
@@ -1,9 +0,44 @@ | ||
import { Video, YTComment, Playlist, Subscription, VideoCategory, VideoAbuseReportReason, Language, Region, ChannelSection, Caption } from '..'; | ||
import YouTube, { Video, YTComment, Playlist, Subscription, VideoCategory, VideoAbuseReportReason, Language, Region, ChannelSection, Caption } from '..'; | ||
/** | ||
* @ignore | ||
*/ | ||
export declare type PaginatedItemsEndpoints = 'playlistItems' | 'playlists' | 'playlists:channel' | 'commentThreads' | 'commentThreads:video' | 'commentThreads:channel' | 'comments' | 'subscriptions' | 'videoCategories' | 'videoAbuseReportReasons' | 'i18nLanguages' | 'i18nRegions' | 'channelSections' | 'captions'; | ||
export declare enum PaginatedItemType { | ||
VideoCategories = 0, | ||
VideoAbuseReportReasons = 1, | ||
Languages = 2, | ||
Regions = 3, | ||
PlaylistItems = 4, | ||
VideoComments = 5, | ||
ChannelComments = 6, | ||
CommentReplies = 7, | ||
Captions = 8, | ||
Playlists = 9, | ||
Subscriptions = 10, | ||
ChannelSections = 11 | ||
} | ||
/** | ||
* @ignore | ||
*/ | ||
export declare type PaginatedItemsReturns = Video[] | YTComment[] | Playlist[] | Subscription[] | VideoCategory[] | VideoAbuseReportReason[] | Language[] | Region[] | ChannelSection[] | Caption[]; | ||
export type PaginatedItemOptions = { | ||
youtube: YouTube; | ||
type: PaginatedItemType; | ||
mine?: boolean; | ||
id?: string; | ||
maxPerPage?: number; | ||
pages?: number; | ||
pageToken?: string; | ||
subId?: string; | ||
parts?: string[]; | ||
}; | ||
export type PageOptions = { | ||
pages?: number; | ||
maxPerPage?: number; | ||
}; | ||
/** | ||
* @ignore | ||
*/ | ||
export type PaginatedItemsReturns = { | ||
results: (Video | YTComment | Playlist | Subscription | VideoCategory | VideoAbuseReportReason | Language | Region | ChannelSection | Caption)[]; | ||
prevPageToken?: string; | ||
nextPageToken?: string; | ||
}; |
@@ -9,1 +9,2 @@ export * from './Thumbnail'; | ||
export * from './ChannelSectionType'; | ||
export * from './Parts'; |
/** | ||
* @ignore | ||
*/ | ||
export declare type ISODuration = { | ||
export type ISODuration = { | ||
weeks: number; | ||
@@ -6,0 +6,0 @@ years: number; |
@@ -1,2 +0,2 @@ | ||
export declare type Thumbnail = { | ||
export type Thumbnail = { | ||
url?: string; | ||
@@ -3,0 +3,0 @@ width?: number; |
@@ -1,2 +0,2 @@ | ||
export declare type VideoUpdateResource = { | ||
export type VideoUpdateResource = { | ||
id: string; | ||
@@ -3,0 +3,0 @@ snippet?: { |
@@ -1,2 +0,2 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" resolution-mode="require"/> | ||
/** | ||
@@ -3,0 +3,0 @@ * @ignore |
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
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
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1581480
118
11064
33