Skip to main content
Module

x/youtubei/deno.ts>default

A wrapper around YouTube's internal API — reverse engineering InnerTube
Very Popular
Go to Latest
class default
import { default } from "https://deno.land/x/youtubei@v9.3.0-deno/deno.ts";

Provides access to various services and modules in the YouTube API.

Constructors

new
default(
session: Session,
cookie?: string,
fetch?: FetchFunction,
)

Properties

readonly
fetch_function: FetchFunction

Methods

fetch(input: URL | Request | string, init?: RequestInit & HTTPClientInit): Promise<Response>

Constructors

new
default(session: Session)

Properties

readonly
account

An interface for managing and retrieving account information.

readonly
actions

An internal class used to dispatch requests.

readonly
interact

An interface for directly interacting with certain YouTube features.

readonly
kids

An interface for interacting with YouTube Kids.

readonly
music

An interface for interacting with YouTube Music.

readonly
playlist

An interface for managing playlists.

readonly
session

The session used by this instance.

readonly
studio

An interface for interacting with YouTube Studio.

Methods

call<T extends IParsedResponse>(endpoint: NavigationEndpoint, args: { [key: string]: any; parse: true; }): Promise<T>

Utility method to call an endpoint without having to use Actions.

call(endpoint: NavigationEndpoint, args?: { [key: string]: any; parse?: false; }): Promise<ApiResponse>
download(video_id: string, options?: DownloadOptions): Promise<ReadableStream<Uint8Array>>

Downloads a given video. If you only need the direct download link see getStreamingData. If you wish to retrieve the video info too, have a look at getBasicInfo or getInfo.

getBasicInfo(video_id: string, client?: InnerTubeClient): Promise<VideoInfo>

Retrieves basic video info.

getChannel(id: string): Promise<Channel>

Retrieves contents for a given channel.

Retrieves Channels feed.

getComments(video_id: string, sort_by?: "TOP_COMMENTS" | "NEWEST_FIRST"): Promise<Comments>

Retrieves comments for a video.

getGuide(): Promise<Guide>

Retrieves YouTube's content guide.

getHashtag(hashtag: string): Promise<HashtagFeed>

Retrieves a given hashtag's page.

getHistory(): Promise<History>

Retrieves watch history. Which can also be achieved with getLibrary.

getHomeFeed(): Promise<HomeFeed>

Retrieves YouTube's home feed (aka recommendations).

getInfo(target: string | NavigationEndpoint, client?: InnerTubeClient): Promise<VideoInfo>

Retrieves video info.

getLibrary(): Promise<Library>

Returns the account's library.

Retrieves notifications.

getPlaylist(id: string): Promise<Playlist>

Retrieves playlist contents.

getSearchSuggestions(query: string): Promise<string[]>

Retrieves search suggestions for a given query.

getShortsWatchItem(short_id: string, client?: InnerTubeClient): Promise<ShortsVideoInfo>

Retrieves shorts info.

getStreamingData(video_id: string, options?: FormatOptions): Promise<Format>

An alternative to download. Returns deciphered streaming data.

If you wish to retrieve the video info too, have a look at getBasicInfo or getInfo.

Retrieves Subscriptions feed.

Retrieves Trending content.

getUnseenNotificationsCount(): Promise<number>

Retrieves unseen notifications count.

resolveURL(url: string): Promise<NavigationEndpoint>

Resolves the given URL.

search(query: string, filters?: SearchFilters): Promise<Search>

Searches a given query.

Constructors

new
default(
context: Context,
api_key: string,
api_version: string,
account_index: number,
player?: Player,
cookie?: string,
fetch?: FetchFunction,
cache?: ICache,
)

Properties

readonly
account_index: number
actions: Actions
readonly
api_version: string

InnerTube API version.

optional
cache: ICache
readonly
client_name: string
readonly
client_version: string
readonly
context: Context
readonly
key: string

InnerTube API key.

readonly
lang: string
logged_in: boolean
oauth: OAuth
readonly
player: Player | undefined

Methods

on(type: "auth", listener: OAuthAuthEventHandler): void
on(type: "auth-pending", listener: OAuthAuthPendingEventHandler): void
on(type: "auth-error", listener: OAuthAuthErrorEventHandler): void
on(type: "update-credentials", listener: OAuthAuthEventHandler): void
once(type: "auth", listener: OAuthAuthEventHandler): void
once(type: "auth-pending", listener: OAuthAuthPendingEventHandler): void
once(type: "auth-error", listener: OAuthAuthErrorEventHandler): void
signIn(credentials?: Credentials): Promise<void>
signOut(): Promise<Response | undefined>

Signs out of the current account and revokes the credentials.

Static Methods

getSessionData(
lang?,
location?,
account_index?,
visitor_data?,
enable_safety_mode?,
generate_session_locally?,
device_category?: DeviceCategory,
client_name?: ClientType,
tz?: string,
fetch?: FetchFunction,
on_behalf_of_user?: string,
)

Constructors

new
default(session: Session)

Properties

readonly
session: Session

Methods

execute<T extends InnertubeEndpoint>(endpoint: T, args: { [key: string]: any; parse: true; protobuf?: false; serialized_data?: any; }): Promise<ParsedResponse<T>>

Executes an API call.

execute<T extends InnertubeEndpoint>(endpoint: T, args?: { [key: string]: any; parse?: false; protobuf?: true; serialized_data?: any; }): Promise<ApiResponse>
stats(
url: string,
client: { client_name: string; client_version: string; },
params: { [key: string]: any; },
): Promise<Response>

Makes calls to the playback tracking API.

Constructors

new
default(
signature_timestamp: number,
sig_sc: string,
nsig_sc: string,
player_id: string,
)

Properties

readonly
nsig_sc: string
readonly
sig_sc: string
readonly
sts: number
readonly
url: string

Methods

cache(cache?: ICache): Promise<void>
decipher(
url?: string,
signature_cipher?: string,
cipher?: string,
this_response_nsig_cache?: Map<string, string>,
): string

Static Properties

readonly
LIBRARY_VERSION: number
TAG: string

Static Methods

create(cache: ICache | undefined, fetch?: FetchFunction): Promise<Player>
extractNSigSourceCode(data: string): string
extractSigSourceCode(data: string): string
extractSigTimestamp(data: string): number
fromCache(cache: ICache, player_id: string): Promise<Player | null>
fromSource(
cache: ICache | undefined,
sig_timestamp: number,
sig_sc: string,
nsig_sc: string,
player_id: string,
): Promise<Player>

Constructors

new
default(session: Session)

Properties

readonly
credentials: Credentials | undefined
readonly
has_access_token_expired: boolean

Methods

cacheCredentials(): Promise<void>
init(credentials?: Credentials): Promise<void>

Starts the auth flow in case no valid credentials are available.

refreshIfRequired(): Promise<void>

Refresh access token if the same has expired.

removeCache(): Promise<void>
revokeCredentials(): Promise<Response | undefined>
validateCredentials(): this is this & { credentials: Credentials; }