/** * @module Library Exports */ import { Request } from './util'; import * as Part from './types/Parts'; import * as T from './types'; import * as Service from './services'; import OAuth from './oauth'; import * as Entity from './entities'; export * from './entities'; export * from './types'; export * from './util/request'; /** * The main class used to interact with the YouTube API. Use this. */ export declare class YouTube { #private; /** * Should be checked BEFORE running any _cache methods. * @ignore */ _shouldCache: boolean; /** * @ignore */ _cacheSearches: boolean; /** * @ignore */ _cacheTTL: number; /** * @ignore */ _cacheCheckInterval: number; /** * @ignore */ _services: { search: Service.SearchService; resolution: Service.ResolutionService; retrieval: Service.RetrievalService; }; /** * Methods requiring an OAuth token. */ oauth: OAuth; /** * The language for the API to respond in. See [`YouTube.getLanguages()`](#getlanguages). */ language: string; /** * The region for the API cater responses to. See [`YouTube.getRegions()`](#getregions). */ region: string; /** * * @param apiKey Your YouTube Data API key. Don't share this with anybody. * @param accessToken A Google OAuth access token. Used for [`YouTube.oauth`](#oauth) methods. * @param options Caching options. Recommended to change. * @param language The language for the API to respond in. See [`YouTube.getLanguages()`](#getlanguages). * @param region The region for the API to cater responses to. See [`YouTube.getRegions()`](#getregions).. */ constructor(apiKey?: string, accessToken?: string, options?: YouTubeOptions, language?: string, region?: string); /** * @ignore */ _cacheItem(type: T.ItemTypes, name: string, value: InstanceType, parts?: string[]): void; /** * @ignore */ _cacheItems(type: T.ItemTypes, names: string[], values: InstanceType[], parts?: string[]): void; /** * @ignore */ _cacheResolution(type: T, input: string, value: T.Resolvable): void; /** * @ignore */ _cachePage(endpoint: string, page: number, options: T.PaginatedRequestParams, auth: T.AuthorizationOptions | undefined, parts: string[] | undefined, type: T.PaginatedType | undefined, value: T.PaginatedResponse): void; /** * Search supported entities on YouTube. * @param searchTerm What to search for on YouTube. * @param searchOptions 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. */ search(searchTerm: string, searchOptions?: T.GenericSearchOptions): Promise>>; /** * Search [`Videos`](/docs/api/Library-Exports/classes/Video) on YouTube. * @param searchTerm What to search for on YouTube. * @param searchOptions 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. */ searchVideos(searchTerm: string, searchOptions?: T.EntitySearchOptions): Promise>; /** * Search [`Channels`](/docs/api/Library-Exports/classes/Channel) on YouTube. * @param searchTerm What to search for on YouTube. * @param searchOptions 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. */ searchChannels(searchTerm: string, searchOptions?: T.EntitySearchOptions): Promise>; /** * Search [`Playlists`](/docs/api/Library-Exports/classes/Playlist) on YouTube. * @param searchTerm What to search for on YouTube. * @param searchOptions 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. */ searchPlaylists(searchTerm: string, searchOptions?: T.EntitySearchOptions): Promise>; /** * Get a [`Video`](./Video) object from the URL, ID, or search query of a video. * @param videoResolvable The URL, ID, or search query of the video. * @param parts The parts of the video to fetch (saves quota if you aren't using certain properties!) */ getVideo(videoResolvable: T, parts?: Part.VideoParts): Promise extends infer T_1 ? T_1 extends T.ResolveReturn ? T_1 extends any[] ? Entity.Video[] : Entity.Video : never : never>; /** * Get a [`Channel`](./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.](https://support.google.com/youtube/answer/2657968?hl=en) * @param channelResolvable The URL, ID, search query, or handle of the channel. * @param parts The parts of the channel to fetch (saves quota if you aren't using certain properties!) */ getChannel(channelResolvable: T, parts?: Part.ChannelParts): Promise extends infer T_1 ? T_1 extends T.ResolveReturn ? T_1 extends any[] ? Entity.Channel[] : Entity.Channel : never : never>; /** * Get a [`Playlist`](./Playlist) object from the URL, ID, or search query of a playlist. * Meant mostly for getting by URL or ID. * @param playlistResolvable The URL, ID, or search query of the playlist. * @param parts The parts of the playlist to fetch (saves quota if you aren't using certain properties!) */ getPlaylist(playlistResolvable: T, parts?: Part.PlaylistParts): Promise extends infer T_1 ? T_1 extends T.ResolveReturn ? T_1 extends any[] ? Entity.Playlist[] : Entity.Playlist : never : never>; /** * Get a [`Comment`](./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: T, parts?: Part.CommentParts): Promise; /** * Get a [`Subscription`](./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 * @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: T, parts?: Part.SubscriptionParts): Promise; /** * Get a [`VideoCategory`](./VideoCategory) object from the ID of a category. * @param categoryId The ID of the category. */ getCategory(categoryId: T): Promise; /** * Get a [`ChannelSection`](./ChannelSection) object from the ID of a section. * @param sectionId 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: T, parts?: Part.ChannelSectionParts): Promise; /** * Get a [`Subscription`](./Subscription) object from the subscriber and channel of a subscription. * Channels can be passed in the form of ID, URL, or search query. * @param subscriberResolvable A resolvable channel that is the subscriber. * @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: T.ChannelResolvable, channelResolvable: T.ChannelResolvable, parts?: Part.SubscriptionParts): Promise; /** * Get `maxPerPage * pages` videos in a [`Playlist`](./Playlist). * Used mostly internally with [`Playlist.fetchVideos()`](./Playlist#fetchvideos). * @param playlistResolvable The URL, ID, or Title of 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 An object containing page token information for future requests and ***partial* video objects**. */ getPlaylistItems(playlistResolvable: T.PlaylistResolvable, pageOptions?: T.PageOptions, parts?: Part.PlaylistItemParts): Promise>; /** * Get `maxPerPage * pages` [`Comment`](./Comment)s from a [`Video`](./Video). * Used mostly internally with [`Video.fetchComments()`](./Video#fetchcomments). * @param videoResolvable The URL, ID, or Title of 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 An object containing page token information for future requests and **comment objects**. */ getVideoComments(videoResolvable: T.VideoResolvable, pageOptions?: T.PageOptions, order?: 'time' | 'relevance', parts?: Part.CommentThreadParts): Promise>; /** * Get `maxPerPage * pages` of a [`Channel`](./Channel)'s [`Playlist`](./Playlist)s. * Used mostly internally with [`Channel.fetchPlaylists()`](./Channel#fetchplaylists). * @param channelResolvable The Username, URL, or ID of 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 playlists to fetch (saves quota if you aren't using certain properties!) * @returns An object containing page token information for future requests and **playlist objects**. */ getChannelPlaylists(channelResolvable: T.ChannelResolvable, pageOptions?: T.PageOptions, parts?: Part.PlaylistParts): Promise>; /** * Get `maxPerPage * pages` of a [`Channel`](./Channel)'s [`Subscription`](./Subscription)s. * Used mostly internally with [`Channel.fetchSubscriptions()`](./Channel#fetchsubscriptions). * @param channelResolvable The Username, URL, or ID of 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 subscriptions to fetch (saves quota if you aren't using certain properties!) * @returns An object containing page token information for future requests and **subscription objects**. */ getChannelSubscriptions(channelResolvable: T.ChannelResolvable, pageOptions?: T.PageOptions, parts?: Part.SubscriptionParts): Promise>; /** * Get `maxPerPage * pages` replies to a [`Comment`](./Comment). * Used mostly internally with [`Comment.fetchReplies`](./Comment#fetchreplies). * @param commentResolvable The ID or URL of the comment to get replies from. * @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 An object containing page token information for future requests and **comment objects**. */ getCommentReplies(commentResolvable: T.CommentResolvable, pageOptions?: T.PageOptions, parts?: Part.CommentParts): Promise>; /** * Gets the [`ChannelSection`](./ChannelSection)s of a [`Channel`](./Channel). * Used mostly internally with [`Channel.fetchSections`](./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: T.ChannelResolvable, parts?: Part.ChannelSectionParts): Promise; /** * Get the list of video categories in [`this.region`](#region)`. */ getCategories(): Promise; /** * Get a list of languages that YouTube supports. */ getLanguages(): Promise; /** * Get a list of regions that YouTube supports. */ getRegions(): Promise; hasAccessToken(): boolean; setAuthorization(authorization: T.Authorization): void; } export type YouTubeOptions = { /** * Whether or not to cache entities. */ cache?: boolean; /** * How long to cache entities in seconds (0 = unlimited). */ cacheTTL?: number; /** * How often to check for and delete expired cached items in seconds. */ cacheCheckInterval?: number; /** * Whether or not we should cache searches */ cacheSearches?: boolean; /** * A custom internal request object to use instead of the default one. */ request?: Request; }; export default YouTube;