Skip to main content

YouTube

popyt


popyt / Library Exports / YouTube

Class: YouTube

Defined in: index.ts:19

The main class used to interact with the YouTube API. Use this.

Constructors​

Constructor​

new YouTube(apiKey?, accessToken?, options?, language?, region?): YouTube

Defined in: index.ts:89

Parameters​

apiKey?​

string

Your YouTube Data API key. Don't share this with anybody.

accessToken?​

string

A Google OAuth access token. Used for YouTube.oauth methods.

options?​

YouTubeOptions = ...

Caching options. Recommended to change.

language?​

string = 'en_US'

The language for the API to respond in. See YouTube.getLanguages().

region?​

string = 'US'

The region for the API to cater responses to. See YouTube.getRegions()..

Returns​

YouTube

Properties​

language​

language: string

Defined in: index.ts:74

The language for the API to respond in. See YouTube.getLanguages().


oauth​

oauth: OAuth

Defined in: index.ts:69

Methods requiring an OAuth token.


region​

region: string

Defined in: index.ts:79

The region for the API cater responses to. See YouTube.getRegions().

Methods​

getCategories()​

getCategories(): Promise<VideoCategory[]>

Defined in: index.ts:407

Get the list of video categories in this.region`.

Returns​

Promise<VideoCategory[]>


getCategory()​

getCategory<T>(categoryId): Promise<T extends any[] ? VideoCategory[] : VideoCategory>

Defined in: index.ts:271

Get a VideoCategory object from the ID of a category.

Type Parameters​

T​

T extends string | string[]

Parameters​

categoryId​

T

The ID of the category.

Returns​

Promise<T extends any[] ? VideoCategory[] : VideoCategory>


getChannel()​

getChannel<T>(channelResolvable, parts?): Promise<ResolveReturn<T, typeof Channel> extends any[] ? Channel[] : Channel>

Defined in: index.ts:231

Get a Channel object from the URL, ID, search query, or handle of a channel. Beware, support for old custom channel URLs is shoddy. Consider migrating to the new @ system.

Type Parameters​

T​

T extends ChannelResolvable | ChannelResolvable[]

Parameters​

channelResolvable​

T

The URL, ID, search query, or handle of the channel.

parts?​

ChannelParts

The parts of the channel to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<ResolveReturn<T, typeof Channel> extends any[] ? Channel[] : Channel>


getChannelPlaylists()​

getChannelPlaylists(channelResolvable, pageOptions?, parts?): Promise<PaginatedResponse<Playlist>>

Defined in: index.ts:353

Get maxPerPage * pages of a Channel's Playlists. Used mostly internally with Channel.fetchPlaylists().

Parameters​

channelResolvable​

ChannelResolvable

The Username, URL, or ID of the channel.

pageOptions?​

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.

parts?​

PlaylistParts

The parts of the playlists to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<PaginatedResponse<Playlist>>

An object containing page token information for future requests and playlist objects.


getChannelSection()​

getChannelSection<T>(sectionId, parts?): Promise<T extends any[] ? ChannelSection[] : ChannelSection>

Defined in: index.ts:280

Get a ChannelSection object from the ID of a section.

Type Parameters​

T​

T extends string | string[]

Parameters​

sectionId​

T

The ID of the section.

parts?​

ChannelSectionParts

The parts of the channel section to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<T extends any[] ? ChannelSection[] : ChannelSection>


getChannelSections()​

getChannelSections(channelResolvable, parts?): Promise<ChannelSection[]>

Defined in: index.ts:398

Gets the ChannelSections of a Channel. Used mostly internally with Channel.fetchSections.

Parameters​

channelResolvable​

ChannelResolvable

The Username, URL, or ID of the channel to get the sections from.

parts?​

ChannelSectionParts

The parts of the channel sections to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<ChannelSection[]>

Partial channel section objects.


getChannelSubscriptions()​

getChannelSubscriptions(channelResolvable, pageOptions?, parts?): Promise<PaginatedResponse<Subscription>>

Defined in: index.ts:369

Get maxPerPage * pages of a Channel's Subscriptions. Used mostly internally with Channel.fetchSubscriptions().

Parameters​

channelResolvable​

ChannelResolvable

The Username, URL, or ID of the channel.

pageOptions?​

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.

parts?​

SubscriptionParts

The parts of the subscriptions to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<PaginatedResponse<Subscription>>

An object containing page token information for future requests and subscription objects.


getComment()​

getComment<T>(commentId, parts?): Promise<T extends any[] ? Comment[] : Comment>

Defined in: index.ts:252

Get a Comment object from the ID of a comment.

Type Parameters​

T​

T extends string | string[]

Parameters​

commentId​

T

The ID of the comment.

parts?​

CommentParts

The parts of the comment to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<T extends any[] ? Comment[] : Comment>


getCommentReplies()​

getCommentReplies(commentResolvable, pageOptions?, parts?): Promise<PaginatedResponse<Comment>>

Defined in: index.ts:385

Get maxPerPage * pages replies to a Comment. Used mostly internally with Comment.fetchReplies.

Parameters​

commentResolvable​

CommentResolvable

The ID or URL of the comment to get replies from.

pageOptions?​

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.

parts?​

CommentParts

The parts of the replies to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<PaginatedResponse<Comment>>

An object containing page token information for future requests and comment objects.


getLanguages()​

getLanguages(): Promise<Language[]>

Defined in: index.ts:414

Get a list of languages that YouTube supports.

Returns​

Promise<Language[]>


getPlaylist()​

getPlaylist<T>(playlistResolvable, parts?): Promise<ResolveReturn<T, typeof Playlist> extends any[] ? Playlist[] : Playlist>

Defined in: index.ts:242

Get a Playlist object from the URL, ID, or search query of a playlist. Meant mostly for getting by URL or ID.

Type Parameters​

T​

T extends PlaylistResolvable | PlaylistResolvable[]

Parameters​

playlistResolvable​

T

The URL, ID, or search query of the playlist.

parts?​

PlaylistParts

The parts of the playlist to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<ResolveReturn<T, typeof Playlist> extends any[] ? Playlist[] : Playlist>


getPlaylistItems()​

getPlaylistItems(playlistResolvable, pageOptions?, parts?): Promise<PaginatedResponse<Video>>

Defined in: index.ts:318

Get maxPerPage * pages videos in a Playlist. Used mostly internally with Playlist.fetchVideos().

Parameters​

playlistResolvable​

PlaylistResolvable

The URL, ID, or Title of the playlist.

pageOptions?​

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.

parts?​

PlaylistItemParts

The parts of the videos to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<PaginatedResponse<Video>>

An object containing page token information for future requests and partial video objects.


getRegions()​

getRegions(): Promise<Region[]>

Defined in: index.ts:421

Get a list of regions that YouTube supports.

Returns​

Promise<Region[]>


getSubscription()​

getSubscription<T>(subscriptionId, parts?): Promise<T extends any[] ? Subscription[] : Subscription>

Defined in: index.ts:263

Get a Subscription object from the ID of a subscription.
Fetching a subscription by ID is CURRENTLY BROKEN in the Public YouTube API, see https://issuetracker.google.com/issues/288609601

Type Parameters​

T​

T extends string | string[]

Parameters​

subscriptionId​

T

The ID of the subscription.

parts?​

SubscriptionParts

The parts of the subscription to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<T extends any[] ? Subscription[] : Subscription>


getSubscriptionByChannels()​

getSubscriptionByChannels(subscriberResolvable, channelResolvable, parts?): Promise<Subscription>

Defined in: index.ts:291

Get a Subscription object from the subscriber and channel of a subscription. Channels can be passed in the form of ID, URL, or search query.

Parameters​

subscriberResolvable​

ChannelResolvable

A resolvable channel that is the subscriber.

channelResolvable​

ChannelResolvable

A resolvable channel that is the channel being subscribed to.

parts?​

SubscriptionParts

The parts of the subscription to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<Subscription>


getVideo()​

getVideo<T>(videoResolvable, parts?): Promise<ResolveReturn<T, typeof Video> extends any[] ? Video[] : Video>

Defined in: index.ts:219

Get a Video object from the URL, ID, or search query of a video.

Type Parameters​

T​

T extends VideoResolvable | VideoResolvable[]

Parameters​

videoResolvable​

T

The URL, ID, or search query of the video.

parts?​

VideoParts

The parts of the video to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<ResolveReturn<T, typeof Video> extends any[] ? Video[] : Video>


getVideoComments()​

getVideoComments(videoResolvable, pageOptions?, order?, parts?): Promise<PaginatedResponse<Comment>>

Defined in: index.ts:335

Get maxPerPage * pages Comments from a Video. Used mostly internally with Video.fetchComments().

Parameters​

videoResolvable​

VideoResolvable

The URL, ID, or Title of the video.

pageOptions?​

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.

order?​

"relevance" | "time"

parts?​

CommentThreadParts

The parts of the comments to fetch (saves quota if you aren't using certain properties!)

Returns​

Promise<PaginatedResponse<Comment>>

An object containing page token information for future requests and comment objects.


hasAccessToken()​

hasAccessToken(): boolean

Defined in: index.ts:425

Returns​

boolean


search<T>(searchTerm, searchOptions?): Promise<PaginatedResponse<InstanceType<T>>>

Defined in: index.ts:173

Search supported entities on YouTube.

Type Parameters​

T​

T extends SearchType = SearchType

Parameters​

searchTerm​

string

What to search for on YouTube.

searchOptions?​

GenericSearchOptions<T>

Options related to the search including search filters, the number of pages, maximum number of results per page, and starting page token. Defaults to the maximum 50 items per page, as well as 1 page. Increase pages as high as you'd like.

Returns​

Promise<PaginatedResponse<InstanceType<T>>>


searchChannels()​

searchChannels(searchTerm, searchOptions?): Promise<PaginatedResponse<Channel>>

Defined in: index.ts:196

Search Channels on YouTube.

Parameters​

searchTerm​

string

What to search for on YouTube.

searchOptions?​

EntitySearchOptions<typeof Channel>

Options related to the search including search filters, the number of pages, maximum number of results per page, and starting page token. Defaults to the maximum 50 items per page, as well as 1 page. Increase pages as high as you'd like.

Returns​

Promise<PaginatedResponse<Channel>>


searchPlaylists()​

searchPlaylists(searchTerm, searchOptions?): Promise<PaginatedResponse<Playlist>>

Defined in: index.ts:207

Search Playlists on YouTube.

Parameters​

searchTerm​

string

What to search for on YouTube.

searchOptions?​

EntitySearchOptions<typeof Playlist>

Options related to the search including search filters, the number of pages, maximum number of results per page, and starting page token. Defaults to the maximum 50 items per page, as well as 1 page. Increase pages as high as you'd like.

Returns​

Promise<PaginatedResponse<Playlist>>


searchVideos()​

searchVideos(searchTerm, searchOptions?): Promise<PaginatedResponse<Video>>

Defined in: index.ts:185

Search Videos on YouTube.

Parameters​

searchTerm​

string

What to search for on YouTube.

searchOptions?​

EntitySearchOptions<typeof Video>

Options related to the search including search filters, the number of pages, maximum number of results per page, and starting page token. Defaults to the maximum 50 items per page, as well as 1 page. Increase pages as high as you'd like.

Returns​

Promise<PaginatedResponse<Video>>


setAuthorization()​

setAuthorization(authorization): void

Defined in: index.ts:429

Parameters​

authorization​

Authorization

Returns​

void