Skip to main content

Documentation

Library Exports.YouTube

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

Constructors

constructor

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

Parameters

NameTypeDefault valueDescription
apiKey?stringundefinedYour YouTube Data API v3 key. Don't share this with anybody.
accessToken?stringundefinedA Google OAuth 2.0 access token. Used for YouTube.oauth methods.
optionsYouTubeOptionsundefinedCaching options. Recommended to change.
languagestring'en_US'The language for the API to respond in. See YouTube.getLanguages().
regionstring'US'The region for the API cater responses to. See YouTube.getRegions()..

Defined in

index.ts:84

Properties

#auth

Private #auth: Authorization = {}

Defined in

index.ts:59


language

language: string

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

Defined in

index.ts:69


oauth

oauth: OAuth

Methods requiring an OAuth token.

Defined in

index.ts:64


region

region: string

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

Defined in

index.ts:74

Methods

getCategories

getCategories(): Promise\<VideoCategory[]>

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

Returns

Promise\<VideoCategory[]>

Defined in

index.ts:401


getCategory

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

Get a VideoCategory object from the ID of a category.

Type parameters

NameType
Textends string | string[]

Parameters

NameTypeDescription
categoryIdTThe ID of the category.

Returns

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

Defined in

index.ts:265


getChannel

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

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

NameType
Textends ChannelResolvable | ChannelResolvable[]

Parameters

NameTypeDescription
channelResolvableTThe URL, ID, search query, or handle of the channel.
parts?ChannelPartsThe 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>

Defined in

index.ts:225


getChannelPlaylists

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

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

Parameters

NameTypeDescription
channelResolvableChannelResolvableThe Username, URL, or ID of the channel.
pageOptions?PageOptionsThe 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?PlaylistPartsThe 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.

Defined in

index.ts:347


getChannelSection

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

Get a ChannelSection object from the ID of a section.

Type parameters

NameType
Textends string | string[]

Parameters

NameTypeDescription
sectionIdT-
parts?ChannelSectionPartsThe parts of the channel section to fetch (saves quota if you aren't using certain properties!)

Returns

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

Defined in

index.ts:274


getChannelSections

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

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

Parameters

NameTypeDescription
channelResolvableChannelResolvableThe Username, URL, or ID of the channel to get the sections from.
parts?ChannelSectionPartsThe parts of the channel sections to fetch (saves quota if you aren't using certain properties!)

Returns

Promise\<ChannelSection[]>

Partial channel section objects.

Defined in

index.ts:392


getChannelSubscriptions

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

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

Parameters

NameTypeDescription
channelResolvableChannelResolvableThe Username, URL, or ID of the channel.
pageOptions?PageOptionsThe 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?SubscriptionPartsThe 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.

Defined in

index.ts:363


getComment

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

Get a Comment object from the ID of a comment.

Type parameters

NameType
Textends string | string[]

Parameters

NameTypeDescription
commentIdTThe ID of the comment.
parts?CommentPartsThe parts of the comment to fetch (saves quota if you aren't using certain properties!)

Returns

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

Defined in

index.ts:246


getCommentReplies

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

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

Parameters

NameTypeDescription
commentResolvableCommentResolvable-
pageOptions?PageOptionsThe 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?CommentPartsThe 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.

Defined in

index.ts:379


getLanguages

getLanguages(): Promise\<Language[]>

Get a list of languages that YouTube supports.

Returns

Promise\<Language[]>

Defined in

index.ts:408


getPlaylist

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

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

Type parameters

NameType
Textends PlaylistResolvable | PlaylistResolvable[]

Parameters

NameTypeDescription
playlistResolvableTThe URL, ID, or search query of the playlist.
parts?PlaylistPartsThe 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>

Defined in

index.ts:236


getPlaylistItems

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

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

Parameters

NameTypeDescription
playlistResolvablePlaylistResolvableThe URL, ID, or Title of the playlist.
pageOptions?PageOptionsThe 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?PlaylistItemPartsThe 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.

Defined in

index.ts:312


getRegions

getRegions(): Promise\<Region[]>

Get a list of regions that YouTube supports.

Returns

Promise\<Region[]>

Defined in

index.ts:415


getSubscription

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

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

NameType
Textends string | string[]

Parameters

NameTypeDescription
subscriptionIdTThe ID of the subscription.
parts?SubscriptionPartsThe parts of the subscription to fetch (saves quota if you aren't using certain properties!)

Returns

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

Defined in

index.ts:257


getSubscriptionByChannels

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

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

NameTypeDescription
subscriberResolvableChannelResolvableA resolvable channel that is the subscriber.
channelResolvableChannelResolvableA resolvable channel that is the channel being subscribed to.
parts?SubscriptionPartsThe parts of the subscription to fetch (saves quota if you aren't using certain properties!)

Returns

Promise\<Subscription>

Defined in

index.ts:285


getVideo

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

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

Type parameters

NameType
Textends VideoResolvable | VideoResolvable[]

Parameters

NameTypeDescription
videoResolvableTThe URL, ID, or search query of the video.
parts?VideoPartsThe 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>

Defined in

index.ts:213


getVideoComments

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

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

Parameters

NameTypeDescription
videoResolvableVideoResolvableThe URL, ID, or Title of the video.
pageOptions?PageOptionsThe 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?"time" | "relevance"-
parts?CommentThreadPartsThe 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.

Defined in

index.ts:329


hasAccessToken

hasAccessToken(): boolean

Returns

boolean

Defined in

index.ts:419


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

Search supported entities on YouTube.

Type parameters

NameType
Textends SearchType = SearchType

Parameters

NameTypeDescription
searchTermstringWhat 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>>>

Defined in

index.ts:167


searchChannels

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

Search channels on YouTube.

Parameters

NameTypeDescription
searchTermstringWhat 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>>

Defined in

index.ts:190


searchPlaylists

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

Search playlists on YouTube.

Parameters

NameTypeDescription
searchTermstringWhat 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>>

Defined in

index.ts:201


searchVideos

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

Search videos on YouTube.

Parameters

NameTypeDescription
searchTermstringWhat 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>>

Defined in

index.ts:179


setAuthorization

setAuthorization(authorization): void

Parameters

NameType
authorizationAuthorization

Returns

void

Defined in

index.ts:423