9.1 KiB
YouTube.js
A full-featured wrapper around the Innertube API, which is what YouTube itself uses.
WIP- Documentation for YouTube.js 2.0.0
Table of Contents
About
Innertube is an API used across all YouTube clients, it was created to simplify1 the internal structure of the platform in a way that updates, tweaks, and experiments can be easily made. This library handles all the low-level communication with Innertube, providing a simple, fast, and efficient way to interact with YouTube programmatically.
And huge thanks to @gatecrasher777 for his research on the workings of the Innertube API!
Getting Started
Prerequisites
- NodeJS v14 or greater
To verify things are set up properly, run this:
node --version
Installation
- NPM:
npm install youtubei.js@latest
- Yarn:
yarn add youtubei.js@latest
- Git (bleeding-edge version):
npm install git+https://github.com/LuanRT/YouTube.js.git
Usage
Create an Innertube instance (or session):
// const Innertube = require('youtubei.js');
import Innertube from 'youtubei.js';
const youtube = await new Innertube({ gl: 'US' });
API
Innertube : object
- Innertube :
object- .getInfo(video_id) ⇒
function - .getBasicInfo(video_id) ⇒
function - .search(query, filters?) ⇒
function
- .getInfo(video_id) ⇒
getInfo(video_id)
Retrieves video info, including playback data and even layout elements such as menus, buttons etc — all nicely parsed.
Returns: Promise.<VideoInfo>
| Param | Type | Description |
|---|---|---|
| video_id | string |
The id of the video |
Methods & Getters:
-
- Likes the video.
-
- Dislikes the video.
-
- Removes like/dislike.
-
- Returns filters that can be applied to the watch next feed.
-
- Applies given filter to the watch next feed and returns a new instance of
VideoInfo.
- Applies given filter to the watch next feed and returns a new instance of
-
<info>#getWatchNextContinuation()- Retrieves next batch of items for the watch next feed.
-
- Returns original InnerTube response (sanitized).
getBasicInfo(video_id)
Suitable for cases where you only need basic video metadata, much faster than getInfo().
Returns: Promise.<VideoInfo>
| Param | Type | Description |
|---|---|---|
| video_id | string |
The id of the video |
search(query, filters?)
Searches the given query on YouTube.
Returns: Promise.<Search>
| Param | Type | Description |
|---|---|---|
| query | string |
The search query |
| filters | object |
Search filters |
Supported search filters:
- type:
all|video|channel|playlist|movie - upload_date:
all|hour|today|week|month|year - duration:
all|short|medium|long - sort_by:
relevance|rating|upload_date|view_count
Methods & Getters:
-
<search>#selectRefinementCard(SearchRefinementCard | string)- Applies given refinement card and returns a new Search instance.
-
<search>#refinement_card_queries- Returns available refinement cards, this is a simplified version of the refinement cards object.
-
- Retrieves next batch of results.
getHomeFeed()
Retrieves YouTube's home feed.
Returns: Promise.<FilterableFeed>
Contributing
Contributions, issues and feature requests are welcome. Feel free to check issues page if you want to contribute.
Contributors
Contact
LuanRT - @lrt_nooneknows - luan.lrt4@gmail.com
Project Link: https://github.com/LuanRT/YouTube.js
Disclaimer
This project is not affiliated with, endorsed, or sponsored by YouTube or any of their affiliates or subsidiaries. All trademarks, logos and brand names are the property of their respective owners, and are used only to directly describe the services being provided, as such, any usage of trademarks to refer to such services is considered nominative use.
Should you have any questions or concerns please contact me directly via email.
License
Distributed under the MIT License.