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:94

Properties

#auth

Private #auth: Authorization = {}

Defined in

index.ts:69


language

language: string

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

Defined in

index.ts:79


oauth

oauth: OAuth

Methods requiring an OAuth token.

Defined in

index.ts:74


region

region: string

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

Defined in

index.ts:84

Methods

getCategories

getCategories(): Promise<VideoCategory[]>

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

Returns

Promise<VideoCategory[]>

Defined in

index.ts:366


getCategory

getCategory<T>(categoryId): Promise<ItemReturns<T, typeof 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<ItemReturns<T, typeof VideoCategory>>

Defined in

index.ts:241


getChannel

getChannel<T>(channelResolvable, parts?): Promise<ItemReturns<ResolveReturn<T, typeof Channel>, typeof 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<ItemReturns<ResolveReturn<T, typeof Channel>, typeof Channel>>

Defined in

index.ts:201


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:312


getChannelSection

getChannelSection<T>(sectionId, parts?): Promise<ItemReturns<T, typeof 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<ItemReturns<T, typeof ChannelSection>>

Defined in

index.ts:250


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:357


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:328


getComment

getComment<T>(commentId, parts?): Promise<ItemReturns<T, typeof 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<ItemReturns<T, typeof Comment>>

Defined in

index.ts:222


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:344


getLanguages

getLanguages(): Promise<Language[]>

Get a list of languages that YouTube supports.

Returns

Promise<Language[]>

Defined in

index.ts:373


getPlaylist

getPlaylist<T>(playlistResolvable, parts?): Promise<ItemReturns<ResolveReturn<T, typeof Playlist>, typeof 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<ItemReturns<ResolveReturn<T, typeof Playlist>, typeof Playlist>>

Defined in

index.ts:212


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:277


getRegions

getRegions(): Promise<Region[]>

Get a list of regions that YouTube supports.

Returns

Promise<Region[]>

Defined in

index.ts:380


getSubscription

getSubscription<T>(subscriptionId, parts?): Promise<ItemReturns<T, typeof 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<ItemReturns<T, typeof Subscription>>

Defined in

index.ts:233


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:261


getVideo

getVideo<T>(videoResolvable, parts?): Promise<ItemReturns<ResolveReturn<T, typeof Video>, typeof 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<ItemReturns<ResolveReturn<T, typeof Video>, typeof Video>>

Defined in

index.ts:189


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:294


hasAccessToken

hasAccessToken(): boolean

Returns

boolean

Defined in

index.ts:384


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:146


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:169


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:180


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:158


setAuthorization

setAuthorization(authorization): void

Parameters

NameType
authorizationAuthorization

Returns

void

Defined in

index.ts:388