An object-oriented wrapper around the Innertube API, which is what YouTube itself uses.
Innertube is an API used across all YouTube clients, it was [made to simplify](https://gizmodo.com/how-project-innertube-helped-pull-youtube-out-of-the-gu-1704946491) the internal structure of the platform and make it easy to push updates. This library takes advantage of that API, therefore providing a simple & efficient way to interact with YouTube programmatically. And big thanks to [@gatecrasher777](https://github.com/gatecrasher777/ytcog) for his research on the workings of the Innertube API! #### What can it do? As of now, this is one of the most advanced & stable YouTube libraries out there, here's a short summary of its features: - Search videos, playlists, music, albums etc - Get detailed info about any video or playlist - Fetch live chat & live stats in real time - Get notifications - Get watch history - Get subscriptions/home feed - Change notification preferences for a channel - Subscribe/Unsubscribe/Like/Dislike/Comment etc - Easily sign in to any Google Account - Change an account's settings. - Download videos Do note that you must be signed-in to perform actions that involve an account, such as commenting, subscribing, sending messages to a live chat, etc. #### Do I need an API key to use this? No, YouTube.js does not use any official API so no API keys are required. ## Installation ```bash npm install youtubei.js ``` ## Usage [1. Getting Started](#usage) [2. Interactions](#interactions) [3. Live chats](#fetching-live-chats) [4. Downloading videos](#downloading-videos) [5. Signing-in](#signing-in) [6. Disclaimer](#disclaimer) First of all we're gonna start by initializing the Innertube instance. And to make things faster, you should do this only once and reuse the Innertube object when needed. ```js const Innertube = require('youtubei.js'); const youtube = await new Innertube(); ``` Doing a simple search: ```js // YouTube: const search = await youtube.search('Looking for life on Mars - Documentary'); // YTMusic: const search = await youtube.search('Interstellar Main Theme', { client: 'YTMUSIC' }); ```
```js { query: string, corrected_query: string, estimated_results: number, videos: [ { id: string, title: string, description: string, url: string, metadata:{ view_count: string, short_view_count_text: { simple_text: string, accessibility_label: string }, thumbnails: [Array], duration: { seconds: number, simple_text: string, accessibility_label: string }, published: string, badges:[Array], owner_badges:[Array] } } //... ] } ```
```js { songs: [ { id: string, title: string, artist: string, album: string, duration: string, thumbnail: { thumbnails: [Array] } }, //... ], videos: [ { id: string, title: string, author: string, views: string, duration: string, thumbnail: { thumbnails: [Array] } } //... ], albums: [ { title: string, author: string, year: string, thumbnail: { thumbnails: [Array] } }, //... ], playlists: [ { title: string, description: string, total_items: number, duration: string, year: string, items: [ { id: string, title: string, author: string, duration: string, thumbnail: [Array] } ] } ] } ```
```js [ { text: string, bold_text: string }, //... ] ```
```js { title: string, description: string, thumbnail: { url: string, width: number, height: number }, metadata: { embed: { iframeUrl: string, flashUrl: string, width: number, height: number, flashSecureUrl: string }, likes: number, dislikes: number, view_count: number, average_rating: number, length_seconds: number, channel_id: string, channel_url: string, external_channel_id: string, allow_ratings: boolean, is_live_content: boolean, is_family_safe: boolean, is_unlisted: boolean, is_private: boolean, is_liked: boolean, is_disliked: boolean, is_subscribed: boolean, subscriber_count: string, current_notification_preference: string, likes: { count: number, short_count_text: string }, publish_date_text: string, has_ypc_metadata: boolean, category: string, channel_name: string, publish_date: string, upload_date: string, keywords: [Array] } } ```
```js { comments: [ { text: string, author: { name: string, thumbnail: [ { url: string, width: number, height: number } ], channel_id: string }, metadata:{ published: string, is_liked: boolean, is_channel_owner: boolean, like_count: number, reply_count: number, id: string } }, //... ], comment_count: string // not available in continuations } ```
```js [ { id: string, title: string, description: string, channel: string, metadata: { view_count: string, short_view_count_text: { simple_text: string, accessibility_label: string }, thumbnail: { url: string, width: number, height: number }, moving_thumbnail: { url: string, width: number, height: number }, published: string, duration: { seconds: number, simple_text: string, accessibility_label: string }, badges: string, owner_badges: [Array] } } // ... ] ```
```js { today: [ { id: string, title: string, channel: string, metadata: { view_count: string, short_view_count_text: { simple_text: string, accessibility_label: string }, thumbnail: { url: string, width: number, height: number }, moving_thumbnail: { url: string, width: number, height: number }, published: string, badges: string, owner_badges: [Array] } } //... ], yesterday: [ { id: string, title: string, channel: string, metadata: { view_count: string, short_view_count_text: { simple_text: string, accessibility_label: string }, thumbnail: { url: string, width: number, height: number }, moving_thumbnail: { url: string, width: number, height: number }, published: string, badges: string, owner_badges: [Array] } } //... ], this_week: [ id: string, title: string, channel: string, metadata: { view_count: string, thumbnail: { url: string, width: number, height: number }, moving_thumbnail: { url: string, width: number, height: number }, published: string, badges: string, owner_badges: [Array] } } // ... ] } ```
```js [ { id: string, title: string, description: string, channel: { name: string, url: string }, metadata: { view_count: string, short_view_count_text: { simple_text: string, accessibility_label: string }, thumbnail: { url: string, width: number, height: number }, moving_thumbnail: { url: string, width: number, height: number }, published: string, duration: { seconds: number, simple_text: string, accessibility_label: string }, badges: string, owner_badges: [Array] } } ] ```
```js [ { title: string, sent_time: string, channel_name: string, channel_thumbnail: { url: string, width: number, height: number }, video_thumbnail: { url: string, width: number, height: number }, video_url: string, read: boolean, notification_id: string }, //... ] ```
```js { title: string, description: string, total_items: number, duration: string, year: string, items: [ { id: string, title: string, author: string, duration: string, thumbnail: [Array] }, //... } ```
```js { title: string, description: string, total_items: string, last_updated: string, views: string, items: [ { id: string, title: string, author: string, duration: { seconds: number, simple_text: string, accessibility_label: string }, thumbnail: [Array] }, //... ] } ```
```js { name: string, photo: [ { url: string, width: number, height: number } ], country: string, language: string; } ```
```js { selected_format: { itag: number, mimeType: string, bitrate: number, initRange: { start: string, end: string }, indexRange: { start: string, end: string }, lastModified: string, contentLength: string, quality: string, projectionType: string, averageBitrate: number, highReplication: boolean, audioQuality: string, approxDurationMs: string, audioSampleRate: string, audioChannels: number, loudnessDb: number, url: string, has_audio: boolean, has_video: boolean }, formats: [ { itag: number, mimeType: string, bitrate: number, initRange: { start: string, end: string }, indexRange: { start: string, end: string }, lastModified: string, contentLength: string, quality: string, projectionType: string, averageBitrate: number, highReplication: boolean, audioQuality: string, approxDurationMs: string, audioSampleRate: string, audioChannels: number, loudnessDb: number, url: string, has_audio: boolean, has_video: boolean } //... ] } ```