mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-13 17:42:18 +00:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
389b0f362f | ||
|
|
6ce4a89766 | ||
|
|
4d7573c46f | ||
|
|
445de3546d | ||
|
|
3b265119d6 | ||
|
|
933ec50a1c | ||
|
|
922ab51a8d | ||
|
|
330943cbc0 | ||
|
|
368dfc4ea3 | ||
|
|
3a9d8a411e | ||
|
|
47ea630329 | ||
|
|
c8e8f34a83 | ||
|
|
14a5b0f0e8 | ||
|
|
e817eb46d4 | ||
|
|
6ca6e22fea | ||
|
|
d11d03bd92 | ||
|
|
27962242b7 | ||
|
|
f54993e3b7 | ||
|
|
d2ec5ebe9c | ||
|
|
10abf386b4 | ||
|
|
f0360cac69 | ||
|
|
24c11f2c06 | ||
|
|
ff2ca5ad3b | ||
|
|
391a4300c1 | ||
|
|
530e310da6 | ||
|
|
73bac32886 | ||
|
|
8023e74adb | ||
|
|
09ce31061d | ||
|
|
7072485782 | ||
|
|
4bd79e5903 | ||
|
|
028e723226 | ||
|
|
1a68875aad | ||
|
|
de7d52a62c | ||
|
|
b8a2fd01cc | ||
|
|
b9ea6e36c8 | ||
|
|
783e6d2435 | ||
|
|
0b11e441ff | ||
|
|
d7db0d2304 | ||
|
|
d674eef530 | ||
|
|
17aa4edb66 | ||
|
|
656c0fb7b8 | ||
|
|
d4dce16be0 | ||
|
|
80a9ece314 |
2
.github/workflows/node.js.yml
vendored
2
.github/workflows/node.js.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [10.x, 12.x, 14.x, 15.x]
|
||||
node-version: [ 12.x, 14.x, 15.x]
|
||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||
|
||||
steps:
|
||||
|
||||
441
README.md
441
README.md
@@ -1,22 +1,30 @@
|
||||
# YouTube.js
|
||||
|
||||
[](https://github.com/LuanRT/YouTube.js/actions/workflows/node.js.yml)
|
||||
[](https://www.npmjs.com/package/youtubei.js)
|
||||
[](https://www.codefactor.io/repository/github/luanrt/youtube.js)
|
||||
|
||||
An object-oriented wrapper around the Innertube API, which is what YouTube itself uses. This makes YouTube.js fast, simple & efficient. 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, and it can:
|
||||
As of now, this is one of the most advanced & stable YouTube libraries out there, here's a short summary of what it can do:
|
||||
|
||||
- Search.
|
||||
- Get detailed info about videos.
|
||||
- Fetch notifications (sign-in required).
|
||||
- Subscribe/Unsubscribe/Like/Dislike/Comment (sign-in required).
|
||||
- Search videos
|
||||
- Get detailed info about any video
|
||||
- Fetch live chat & live stats in real time
|
||||
- Fetch notifications
|
||||
- Fetch subscriptions feed
|
||||
- Change notifications preferences for a channel
|
||||
- Subscribe/Unsubscribe/Like/Dislike/Comment
|
||||
- Easily sign into your account in an easy & reliable way.
|
||||
- Last but not least, you can also 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, since it's basically what YouTube itself uses to populate its app/website no API keys are required.
|
||||
No, YouTube.js does not use any official API so no API keys are required.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -30,11 +38,13 @@ npm install youtubei.js
|
||||
|
||||
[2. Interactions](https://github.com/LuanRT/YouTube.js#interactions)
|
||||
|
||||
[3. Downloading Videos](https://github.com/LuanRT/YouTube.js#downloading-videos)
|
||||
[3. Fetching live chats](https://github.com/LuanRT/YouTube.js#fetching-live-chats)
|
||||
|
||||
[4. Signing-in](https://github.com/LuanRT/YouTube.js#signing-in)
|
||||
[4. Downloading videos](https://github.com/LuanRT/YouTube.js#downloading-videos)
|
||||
|
||||
[5. Disclaimer](https://github.com/LuanRT/YouTube.js#disclaimer)
|
||||
[5. Signing-in](https://github.com/LuanRT/YouTube.js#signing-in)
|
||||
|
||||
[6. Disclaimer](https://github.com/LuanRT/YouTube.js#disclaimer)
|
||||
|
||||
First of all we're gonna start by initializing the Innertube class:
|
||||
|
||||
@@ -118,7 +128,7 @@ const search = await youtube.search('Looking for life on Mars - Documentary');
|
||||
|
||||
|
||||
|
||||
Getting details about a specific video:
|
||||
Get details about a specific video:
|
||||
|
||||
```js
|
||||
const video = await youtube.getDetails(search.videos[0].id);
|
||||
@@ -178,8 +188,271 @@ const video = await youtube.getDetails(search.videos[0].id);
|
||||
</p>
|
||||
</details>
|
||||
|
||||
Get comments:
|
||||
|
||||
Fetching notifications:
|
||||
```js
|
||||
const video = await youtube.getDetails(VIDEO_ID_HERE);
|
||||
const comments = await video.getComments();
|
||||
|
||||
// If you want to load more comments simply call:
|
||||
const comments_continuation = await comments.getContinuation();
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Output</summary>
|
||||
<p>
|
||||
|
||||
```js
|
||||
{
|
||||
"comments":[
|
||||
{
|
||||
"text":"The amazing thing to me is the engineering. It's truly remarkable that we can build machines like these.",
|
||||
"author":{
|
||||
"name":"Mark B",
|
||||
"thumbnail":[
|
||||
{
|
||||
"url":"https://yt3.ggpht.com/ytc/AKedOLTKxmup9YqNEMvf-nSdOe7F6CwWhUtu4mpUsg=s48-c-k-c0x00ffffff-no-rj",
|
||||
"width":48,
|
||||
"height":48
|
||||
},
|
||||
{
|
||||
"url":"https://yt3.ggpht.com/ytc/AKedOLTKxmup9YqNEMvf-nSdOe7F6CwWhUtu4mpUsg=s88-c-k-c0x00ffffff-no-rj",
|
||||
"width":88,
|
||||
"height":88
|
||||
},
|
||||
{
|
||||
"url":"https://yt3.ggpht.com/ytc/AKedOLTKxmup9YqNEMvf-nSdOe7F6CwWhUtu4mpUsg=s176-c-k-c0x00ffffff-no-rj",
|
||||
"width":176,
|
||||
"height":176
|
||||
}
|
||||
],
|
||||
"channel_id":"UClnPXUOtCLnKsbS2reuN7wg"
|
||||
},
|
||||
"metadata":{
|
||||
"published":"2 months ago",
|
||||
"is_liked":false,
|
||||
"is_channel_owner":false,
|
||||
"like_count":"54",
|
||||
"reply_count":3,
|
||||
"id":"Ugy-bGGepYil_2dAQUp4AaABAg"
|
||||
}
|
||||
},
|
||||
{
|
||||
"text":"May 25th, 2021 and everything has gone perfectly! Ingenuity, moxy and perseverance all working to plan. Unbelievable accomplishments!!!",
|
||||
"author":{
|
||||
"name":"cliff luebke",
|
||||
"thumbnail":[
|
||||
{
|
||||
"url":"https://yt3.ggpht.com/ytc/AKedOLR1_6jvPZa_ycrkUEVxVxo0Alo25e7O8fOcm5v9ww=s48-c-k-c0x00ffffff-no-rj",
|
||||
"width":48,
|
||||
"height":48
|
||||
},
|
||||
{
|
||||
"url":"https://yt3.ggpht.com/ytc/AKedOLR1_6jvPZa_ycrkUEVxVxo0Alo25e7O8fOcm5v9ww=s88-c-k-c0x00ffffff-no-rj",
|
||||
"width":88,
|
||||
"height":88
|
||||
},
|
||||
{
|
||||
"url":"https://yt3.ggpht.com/ytc/AKedOLR1_6jvPZa_ycrkUEVxVxo0Alo25e7O8fOcm5v9ww=s176-c-k-c0x00ffffff-no-rj",
|
||||
"width":176,
|
||||
"height":176
|
||||
}
|
||||
],
|
||||
"channel_id":"UCeVFeX4jCgaJpvNJ4f_I4RA"
|
||||
},
|
||||
"metadata":{
|
||||
"published":"4 months ago",
|
||||
"is_liked":false,
|
||||
"is_channel_owner":false,
|
||||
"like_count":"54",
|
||||
"reply_count":0,
|
||||
"id":"UgylkZHOe7v78hxHPpl4AaABAg"
|
||||
}
|
||||
},
|
||||
//...
|
||||
],
|
||||
"comment_count":"3,231" // not available in continuations
|
||||
}
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
Get subscriptions feed:
|
||||
```js
|
||||
const mysubfeed = await youtube.getSubscriptionsFeed();
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Output</summary>
|
||||
<p>
|
||||
|
||||
```js
|
||||
{
|
||||
"today":[
|
||||
{
|
||||
"title":"Life As My P*nis",
|
||||
"id":"udDINILQH10",
|
||||
"channel":"penguinz0",
|
||||
"metadata":{
|
||||
"view_count":"220,432 views",
|
||||
"thumbnail":[
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/udDINILQH10/hqdefault.jpg?sqp=-oaymwEbCNIBEHZIVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLAQ7bbeUhCxRSg-g-CPek-soixUMQ",
|
||||
"width":210,
|
||||
"height":118
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/udDINILQH10/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLB6fuvBJMeLtkM0TLkZwharsyojjA",
|
||||
"width":246,
|
||||
"height":138
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/udDINILQH10/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDd7BncH1QuZD-Hada_n6dAVRTnmg",
|
||||
"width":336,
|
||||
"height":188
|
||||
}
|
||||
],
|
||||
"published":"2 hours ago",
|
||||
"badges":"N/A",
|
||||
"owner_badges":[
|
||||
"Verified"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"title":"Perseverance and Ingenuity went two weeks without contacting Earth",
|
||||
"id":"VsmYZMVCHuc",
|
||||
"channel":"Mars Guy",
|
||||
"metadata":{
|
||||
"view_count":"2,633 views",
|
||||
"thumbnail":[
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/VsmYZMVCHuc/hqdefault.jpg?sqp=-oaymwEbCNIBEHZIVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLA0-vwAgpFbMO1zG4HTzdHZey1kZQ",
|
||||
"width":210,
|
||||
"height":118
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/VsmYZMVCHuc/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBtM3W-RXsCfPnxgnrktaBkiL9zzg",
|
||||
"width":246,
|
||||
"height":138
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/VsmYZMVCHuc/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDTil7At4FUVYeSNySOoFoKlPXWSA",
|
||||
"width":336,
|
||||
"height":188
|
||||
}
|
||||
],
|
||||
"published":"15 hours ago",
|
||||
"badges":"N/A",
|
||||
"owner_badges":"N/A"
|
||||
}
|
||||
}
|
||||
//...
|
||||
],
|
||||
"yesterday":[
|
||||
{
|
||||
"title":"Fortnite - S.T.A.R.S (Resident Evil) | PS5, PS4",
|
||||
"id":"-ZLEQOVbWD4",
|
||||
"channel":"PlayStation",
|
||||
"metadata":{
|
||||
"view_count":"157,197 views",
|
||||
"thumbnail":[
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/-ZLEQOVbWD4/hqdefault.jpg?sqp=-oaymwEbCNIBEHZIVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLAeA1fLzsEA0ZIouNJuMDJOqOc9Ng",
|
||||
"width":210,
|
||||
"height":118
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/-ZLEQOVbWD4/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDzvhxJ6m2ztykk2ezNH2Din33hEw",
|
||||
"width":246,
|
||||
"height":138
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/-ZLEQOVbWD4/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDo67DvnaiKzOVfNm9lJg_Edd1UDQ",
|
||||
"width":336,
|
||||
"height":188
|
||||
}
|
||||
],
|
||||
"published":"1 day ago",
|
||||
"badges":"N/A",
|
||||
"owner_badges":[
|
||||
"Verified"
|
||||
]
|
||||
}
|
||||
},
|
||||
//...
|
||||
],
|
||||
"this_week":[
|
||||
{
|
||||
"title":"Horrible $100 Million Gold Mansion",
|
||||
"id":"F-d3CEYJyrg",
|
||||
"channel":"penguinz0",
|
||||
"metadata":{
|
||||
"view_count":"693,041 views",
|
||||
"thumbnail":[
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/F-d3CEYJyrg/hqdefault.jpg?sqp=-oaymwEbCNIBEHZIVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLDdMMGG-50O4U5uIcoZ2FoiO6Mopg",
|
||||
"width":210,
|
||||
"height":118
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/F-d3CEYJyrg/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAwqMy1ekLaxWGnjWwCJl7z7Nw2aQ",
|
||||
"width":246,
|
||||
"height":138
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/F-d3CEYJyrg/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLADaPBg0vh52e6clHvUf5otBZO9HA",
|
||||
"width":336,
|
||||
"height":188
|
||||
}
|
||||
],
|
||||
"published":"2 days ago",
|
||||
"badges":"N/A",
|
||||
"owner_badges":[
|
||||
"Verified"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"title":"OOopsieeee",
|
||||
"id":"mJ2WOIhEPm8",
|
||||
"channel":"PewDiePie",
|
||||
"metadata":{
|
||||
"view_count":"1,953,970 views",
|
||||
"thumbnail":[
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/mJ2WOIhEPm8/hqdefault.jpg?sqp=-oaymwEbCNIBEHZIVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLCrJe2a6rasJICj_jchMquZ2YGVrQ",
|
||||
"width":210,
|
||||
"height":118
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/mJ2WOIhEPm8/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCpxERsiLJayuKegeb5mHw3Ok6wGA",
|
||||
"width":246,
|
||||
"height":138
|
||||
},
|
||||
{
|
||||
"url":"https://i.ytimg.com/vi/mJ2WOIhEPm8/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAlRLjypimzrE3GD_iGYDGwTlCGvA",
|
||||
"width":336,
|
||||
"height":188
|
||||
}
|
||||
],
|
||||
"published":"2 days ago",
|
||||
"badges":"N/A",
|
||||
"owner_badges":[
|
||||
"Verified"
|
||||
]
|
||||
}
|
||||
},
|
||||
//...
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
Get notifications:
|
||||
|
||||
```js
|
||||
const notifications = await youtube.getNotifications();
|
||||
@@ -220,7 +493,7 @@ const notifications = await youtube.getNotifications();
|
||||
|
||||
---
|
||||
|
||||
* Subscribing/Unsubscribing to channels:
|
||||
* Subscribe/Unsubscribe:
|
||||
```js
|
||||
const video = await youtube.getDetails(VIDEO_ID_HERE); // this is equivalent to opening the watch page on YouTube
|
||||
|
||||
@@ -228,7 +501,7 @@ await video.subscribe();
|
||||
await video.unsubscribe();
|
||||
```
|
||||
|
||||
* Liking/Disliking:
|
||||
* Like/Dislike:
|
||||
```js
|
||||
const video = await youtube.getDetails(VIDEO_ID_HERE); // this is equivalent to opening the watch page on YouTube
|
||||
|
||||
@@ -237,71 +510,67 @@ await video.dislike();
|
||||
await video.removeLike(); // removes either a like or dislike
|
||||
```
|
||||
|
||||
* Commenting:
|
||||
* Comment:
|
||||
```js
|
||||
const video = await youtube.getDetails(VIDEO_ID_HERE);
|
||||
await video.comment('Haha, nice!');
|
||||
```
|
||||
|
||||
All of the interactions above will return ```{ success: true, status_code: 200 }``` if everything goes alright.
|
||||
|
||||
### Signing-in:
|
||||
---
|
||||
|
||||
This library allows you to sign-in in two different ways:
|
||||
|
||||
- Using OAuth 2.0, easy, simple & reliable.
|
||||
- Cookies, usually more complicated to get and unreliable.
|
||||
|
||||
OAuth 2.0:
|
||||
|
||||
* Change notification preferences:
|
||||
```js
|
||||
const video = await youtube.getDetails(VIDEO_ID_HERE);
|
||||
await video.setNotificationPref('ALL'); // ALL | NONE | PERSONALIZED
|
||||
```
|
||||
|
||||
All of the above interactions will return ```{ success: true, status_code: 200 }``` if everything goes alright.
|
||||
|
||||
### Fetching live chats:
|
||||
---
|
||||
YouTube.js isn't able to download live content yet, but it does allow you to fetch live chats plus you can also send messages!
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const Innertube = require('youtubei.js');
|
||||
const creds_path = './yt_oauth_creds.json';
|
||||
|
||||
async function start() {
|
||||
const creds = fs.existsSync(creds_path) && JSON.parse(fs.readFileSync(creds_path).toString()) || {};
|
||||
const youtube = await new Innertube();
|
||||
|
||||
const search = await youtube.search('Some random live');
|
||||
const video = await youtube.getDetails(search.videos[0].id);
|
||||
|
||||
// Only triggered when signing-in.
|
||||
youtube.on('auth', (data) => {
|
||||
if (data.status === 'AUTHORIZATION_PENDING') {
|
||||
console.info(`Hello!\nOn your phone or computer, go to ${data.verification_url} and enter the code ${data.code}`);
|
||||
} else if (data.status === 'SUCCESS') {
|
||||
fs.writeFileSync(creds_path, JSON.stringify({ access_token: data.access_token, refresh_token: data.refresh_token }));
|
||||
console.info('Successfully signed-in, enjoy!');
|
||||
// This should only be called if you're sure it's a live and that it's still ongoing
|
||||
const livechat = video.getLivechat();
|
||||
|
||||
// Updated stats about the livestream
|
||||
livechat.on('update-metadata', (data) => {
|
||||
console.info('Info:', data);
|
||||
});
|
||||
|
||||
// Fired whenever there is a new message or other chat events
|
||||
livechat.on('chat-update', (message) => {
|
||||
console.info(`- ${message.author.name}\n${message.text}\n\n`);
|
||||
|
||||
if(message.text == '!info') {
|
||||
livechat.sendMessage('Hello! This message was sent from YouTube.js');
|
||||
}
|
||||
});
|
||||
|
||||
// Triggered whenever the access token is refreshed.
|
||||
youtube.on('update-credentials', (data) => {
|
||||
fs.writeFileSync(creds_path, JSON.stringify({ access_token: data.access_token, refresh_token: data.refresh_token }));
|
||||
console.info('Credentials updated!', data);
|
||||
});
|
||||
|
||||
await youtube.signIn(creds);
|
||||
|
||||
//...
|
||||
}
|
||||
|
||||
start();
|
||||
```
|
||||
|
||||
Cookies:
|
||||
|
||||
Stop fetching the live chat:
|
||||
```js
|
||||
const Innertube = require('youtubei.js');
|
||||
livechat.stop();
|
||||
```
|
||||
|
||||
async function start() {
|
||||
const youtube = await new Innertube(COOKIE_HERE);
|
||||
//...
|
||||
}
|
||||
|
||||
start();
|
||||
Deleting a message:
|
||||
```js
|
||||
const msg = await livechat.sendMessage('Nice live!');
|
||||
await msg.deleteMessage();
|
||||
```
|
||||
|
||||
### Downloading videos:
|
||||
---
|
||||
|
||||
YouTube.js provides an easy-to-use and simple downloader:
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
@@ -349,6 +618,65 @@ Cancelling a download:
|
||||
stream.cancel();
|
||||
```
|
||||
|
||||
### Signing-in:
|
||||
---
|
||||
|
||||
This library allows you to sign-in in two different ways:
|
||||
|
||||
- Using OAuth 2.0, easy, simple & reliable.
|
||||
- Cookies, usually more complicated to get and unreliable.
|
||||
|
||||
OAuth:
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const Innertube = require('youtubei.js');
|
||||
const creds_path = './yt_oauth_creds.json';
|
||||
|
||||
async function start() {
|
||||
const creds = fs.existsSync(creds_path) && JSON.parse(fs.readFileSync(creds_path).toString()) || {};
|
||||
const youtube = await new Innertube();
|
||||
|
||||
// Only triggered when signing-in.
|
||||
youtube.on('auth', (data) => {
|
||||
if (data.status === 'AUTHORIZATION_PENDING') {
|
||||
console.info(`Hello!\nOn your phone or computer, go to ${data.verification_url} and enter the code ${data.code}`);
|
||||
} else if (data.status === 'SUCCESS') {
|
||||
fs.writeFileSync(creds_path, JSON.stringify({ access_token: data.access_token, refresh_token: data.refresh_token }));
|
||||
console.info('Successfully signed-in, enjoy!');
|
||||
}
|
||||
});
|
||||
|
||||
// Triggered whenever the access token is refreshed.
|
||||
youtube.on('update-credentials', (data) => {
|
||||
fs.writeFileSync(creds_path, JSON.stringify({ access_token: data.access_token, refresh_token: data.refresh_token }));
|
||||
console.info('Credentials updated!', data);
|
||||
});
|
||||
|
||||
await youtube.signIn(creds);
|
||||
|
||||
//...
|
||||
}
|
||||
|
||||
start();
|
||||
```
|
||||
|
||||
Cookies:
|
||||
|
||||
```js
|
||||
const Innertube = require('youtubei.js');
|
||||
|
||||
async function start() {
|
||||
const youtube = await new Innertube(COOKIE_HERE);
|
||||
//...
|
||||
}
|
||||
|
||||
start();
|
||||
```
|
||||
|
||||
## Note
|
||||
Never sign-in with your personal account, you might get banned if you spam (don't ever do that) or simply because YouTube detected unusual activity coming from your account. Also, I'm not responsible if any of that happens to you.
|
||||
|
||||
## Contributing
|
||||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
||||
|
||||
@@ -358,5 +686,6 @@ This project is not affiliated with, endorsed, or sponsored by YouTube or any of
|
||||
All trademarks, logos and brand names are the property of their respective owners.
|
||||
|
||||
Should you have any questions or concerns please contact me directly via email.
|
||||
|
||||
## License
|
||||
[MIT](https://choosealicense.com/licenses/mit/)
|
||||
@@ -1,17 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const Innertube = require('..');
|
||||
const COOKIE = 'YT_COOKIE_HERE';
|
||||
|
||||
async function start() {
|
||||
const youtube = await new Innertube(COOKIE);
|
||||
const youtube = await new Innertube();
|
||||
|
||||
// Searching, getting details about videos & making interactions:
|
||||
const search = await youtube.search('Looking for life on Mars - documentary');
|
||||
console.info('Search results:', search);
|
||||
|
||||
const video = await youtube.getDetails(search.videos[0].id);
|
||||
|
||||
if (search.videos.length === 0)
|
||||
return console.error('Could not find any video about that on YouTube.');
|
||||
|
||||
const video = await youtube.getDetails(search.videos[0].id).catch((error) => error);
|
||||
console.info('Video details:', video);
|
||||
|
||||
|
||||
if (video instanceof Error)
|
||||
return console.error('Could not get details for ' + search.videos[0].title);
|
||||
|
||||
if (youtube.logged_in) {
|
||||
const myNotifications = await youtube.getNotifications();
|
||||
console.info('My notifications:', myNotifications);
|
||||
@@ -54,7 +61,7 @@ async function start() {
|
||||
type: 'videoandaudio' // can be “video”, “audio” and “videoandaudio”
|
||||
});
|
||||
|
||||
stream.pipe(fs.createWriteStream(`./${search.videos[0].title}.mp4`));
|
||||
stream.pipe(fs.createWriteStream(`./${search.videos[0].id}.mp4`));
|
||||
|
||||
stream.on('start', () => {
|
||||
console.info('[DOWNLOADER]', 'Starting download now!');
|
||||
|
||||
295
lib/Actions.js
295
lib/Actions.js
@@ -3,169 +3,166 @@
|
||||
const Axios = require('axios');
|
||||
const Utils = require('./Utils');
|
||||
const Constants = require('./Constants');
|
||||
const Uuid = require('uuid');
|
||||
|
||||
async function subscribe(session, video_id, channel_id) {
|
||||
if (!session.logged_in) throw new Error('You must be logged in to subscribe to a channel');
|
||||
let data = {
|
||||
context: session.context,
|
||||
channelIds: [channel_id]
|
||||
};
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/subscription/subscribe${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
status_code: response.response.status,
|
||||
message: response.message
|
||||
};
|
||||
} else if (response.data.responseContext) {
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
};
|
||||
async function engage(session, engagement_type, args = {}) {
|
||||
if (!session.logged_in) throw new Error('You are not logged in');
|
||||
let data = {};
|
||||
switch (engagement_type) {
|
||||
case 'like/like':
|
||||
case 'like/dislike':
|
||||
case 'like/removelike':
|
||||
data = {
|
||||
context: session.context,
|
||||
target: {
|
||||
videoId: args.video_id
|
||||
}
|
||||
};
|
||||
break;
|
||||
case 'subscription/subscribe':
|
||||
case 'subscription/unsubscribe':
|
||||
data = {
|
||||
context: session.context,
|
||||
channelIds: [args.channel_id]
|
||||
};
|
||||
break;
|
||||
case 'comment/create_comment':
|
||||
data = {
|
||||
context: session.context,
|
||||
commentText: args.text,
|
||||
createCommentParams: Utils.generateCommentParams(args.video_id)
|
||||
};
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/${engagement_type}${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: args.video_id, data })).catch((error) => error);
|
||||
if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message };
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status
|
||||
};
|
||||
}
|
||||
|
||||
async function unsubscribe(session, video_id, channel_id) {
|
||||
if (!session.logged_in) throw new Error('You must be logged in to unsubscribe from a channel');
|
||||
let data = {
|
||||
context: session.context,
|
||||
channelIds: [channel_id]
|
||||
};
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/subscription/unsubscribe${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
status_code: response.response.status,
|
||||
message: response.message
|
||||
};
|
||||
} else if (response.data.responseContext) {
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
};
|
||||
async function browse(session, action_type) {
|
||||
if (!session.logged_in) throw new Error('You are not logged in');
|
||||
let data;
|
||||
switch (action_type) {
|
||||
case 'subscriptions_feed':
|
||||
data = {
|
||||
context: session.context,
|
||||
browseId: 'FEsubscriptions'
|
||||
};
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/browse${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session })).catch((error) => error);
|
||||
if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message };
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
data: response.data
|
||||
};
|
||||
}
|
||||
|
||||
async function likeVideo(session, video_id) {
|
||||
if (!session.logged_in) throw new Error('You must be logged in to like a video');
|
||||
let data = {
|
||||
context: session.context,
|
||||
target: {
|
||||
videoId: video_id
|
||||
}
|
||||
};
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/like/like${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
status_code: response.response.status,
|
||||
message: response.message
|
||||
};
|
||||
} else if (response.data.responseContext) {
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
};
|
||||
async function notifications(session, action_type, args = {}) {
|
||||
if (!session.logged_in) throw new Error('You are not logged in');
|
||||
let data;
|
||||
switch (action_type) {
|
||||
case 'modify_channel_preference':
|
||||
let pref_types = { PERSONALIZED: 1, ALL: 2, NONE: 3 };
|
||||
data = {
|
||||
context: session.context,
|
||||
params: Utils.encodeNotificationPref(args.channel_id, pref_types[args.pref.toUpperCase()])
|
||||
};
|
||||
break;
|
||||
case 'get_notification_menu':
|
||||
data = {
|
||||
context: session.context,
|
||||
notificationsMenuRequestType: 'NOTIFICATIONS_MENU_REQUEST_TYPE_INBOX'
|
||||
};
|
||||
break;
|
||||
case 'get_unseen_count':
|
||||
data = {
|
||||
context: session.context
|
||||
};
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/notification/${action_type}${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session })).catch((error) => error);
|
||||
if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message };
|
||||
if (action_type === 'modify_channel_preference') return { success: true, status_code: response.status };
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
data: response.data
|
||||
};
|
||||
}
|
||||
|
||||
async function dislikeVideo(session, video_id) {
|
||||
if (!session.logged_in) throw new Error('You must be logged in to like a video');
|
||||
let data = {
|
||||
context: session.context,
|
||||
target: {
|
||||
videoId: video_id
|
||||
}
|
||||
};
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/like/dislike${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
status_code: response.response.status,
|
||||
message: response.message
|
||||
};
|
||||
} else if (response.data.responseContext) {
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
};
|
||||
async function livechat(session, action_type, args = {}) {
|
||||
let data;
|
||||
switch (action_type) {
|
||||
case 'live_chat/send_message':
|
||||
data = {
|
||||
context: session.context,
|
||||
params: Utils.generateMessageParams(args.channel_id, args.video_id),
|
||||
clientMessageId: `INntLiB${Uuid.v4()}`,
|
||||
richMessage: {
|
||||
textSegments: [{ text: args.text }]
|
||||
}
|
||||
};
|
||||
break;
|
||||
case 'live_chat/get_item_context_menu':
|
||||
data = {
|
||||
context: session.context
|
||||
};
|
||||
break;
|
||||
case 'live_chat/moderate':
|
||||
data = {
|
||||
context: session.context,
|
||||
params: args.cmd_params
|
||||
};
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/${action_type}${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, params: args.params })).catch((error) => error);
|
||||
if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message };
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
data: response.data
|
||||
};
|
||||
}
|
||||
|
||||
async function removeLike(session, video_id) {
|
||||
if (!session.logged_in) throw new Error('You must be logged in to remove a like/dislike.');
|
||||
let data = {
|
||||
context: session.context,
|
||||
target: {
|
||||
videoId: video_id
|
||||
}
|
||||
};
|
||||
async function getContinuation(session, info = {}) {
|
||||
let data = { context: session.context };
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/like/removelike${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
status_code: response.response.status,
|
||||
message: response.message
|
||||
};
|
||||
} else if (response.data.responseContext) {
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
};
|
||||
if (info.continuation_token) {
|
||||
data.continuation = info.continuation_token;
|
||||
}
|
||||
|
||||
if (info.video_id) {
|
||||
data.videoId = info.video_id;
|
||||
data.racyCheckOk = true;
|
||||
data.contentCheckOk = false;
|
||||
data.autonavState = 'STATE_NONE';
|
||||
data.playbackContext = {
|
||||
vis: 0,
|
||||
lactMilliseconds: '-1'
|
||||
};
|
||||
data.captionsRequested = false;
|
||||
}
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/next${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session })).catch((error) => error);
|
||||
if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message };
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
data: response.data
|
||||
};
|
||||
}
|
||||
|
||||
async function commentVideo(session, video_id, text) {
|
||||
if (!text) throw new Error('No text was provided');
|
||||
if (!session.logged_in) throw new Error('You must be logged in to post a comment.');
|
||||
|
||||
let data = {
|
||||
context: session.context,
|
||||
commentText: text,
|
||||
createCommentParams: Utils.encodeId(video_id)
|
||||
};
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/comment/create_comment${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
status_code: response.response.status,
|
||||
message: response.message
|
||||
};
|
||||
} else if (response.data.responseContext) {
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function getNotifications(session) {
|
||||
if (!session.logged_in) throw new Error('You must be logged in to fetch notifications');
|
||||
let data = {
|
||||
context: session.context,
|
||||
notificationsMenuRequestType: 'NOTIFICATIONS_MENU_REQUEST_TYPE_INBOX'
|
||||
};
|
||||
|
||||
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/notification/get_notification_menu${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, data, desktop: true })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
status_code: response.response.status,
|
||||
message: response.message
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
data: response.data
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { subscribe, unsubscribe, likeVideo, dislikeVideo, removeLike, commentVideo, getNotifications };
|
||||
module.exports = { engage, browse, notifications, livechat, getContinuation };
|
||||
@@ -43,6 +43,7 @@ const default_headers = (session) => {
|
||||
const innertube_request_opts = (info) => {
|
||||
if (info.desktop === undefined) info.desktop = true;
|
||||
let req_opts = {
|
||||
params: info.params || {},
|
||||
headers: {
|
||||
'accept': '*/*',
|
||||
'user-agent': Utils.getRandomUserAgent(info.desktop ? 'desktop' : 'mobile').userAgent,
|
||||
@@ -63,10 +64,6 @@ const innertube_request_opts = (info) => {
|
||||
req_opts.headers.authorization = info.session.cookie.length < 1 ? `Bearer ${info.session.access_token}` : info.session.auth_apisid;
|
||||
}
|
||||
|
||||
if (info.data) {
|
||||
req_opts.headers['content-length'] = Buffer.byteLength(JSON.stringify(info.data), 'utf8');
|
||||
}
|
||||
|
||||
if (info.id) {
|
||||
req_opts.headers.referer = (info.desktop ? urls.YT_BASE_URL : urls.YT_MOBILE_URL) + '/watch?v=' + info.id;
|
||||
}
|
||||
@@ -161,21 +158,31 @@ const formatVideoData = (data, context, desktop) => {
|
||||
video_details.description = data[2].playerResponse.videoDetails.shortDescription;
|
||||
video_details.thumbnail = data[2].playerResponse.videoDetails.thumbnail.thumbnails.slice(-1)[0];
|
||||
|
||||
// actions
|
||||
video_details.like = like => {};
|
||||
video_details.dislike = dislike => {};
|
||||
video_details.removeLike = remove_like => {};
|
||||
video_details.subscribe = subscribe => {};
|
||||
video_details.unsubscribe = unsubscribe => {};
|
||||
video_details.comment = comment => {};
|
||||
// Functions
|
||||
video_details.like = () => {};
|
||||
video_details.dislike = () => {};
|
||||
video_details.removeLike = () => {};
|
||||
video_details.subscribe = () => {};
|
||||
video_details.unsubscribe = () => {};
|
||||
video_details.comment = () => {};
|
||||
video_details.getComments = () => {};
|
||||
video_details.setNotificationPref = () => {};
|
||||
video_details.getLivechat = () => {};
|
||||
|
||||
// additional metadata
|
||||
// Additional metadata
|
||||
video_details.metadata = metadata;
|
||||
}
|
||||
return video_details;
|
||||
};
|
||||
|
||||
|
||||
const base64_alphabet = {
|
||||
normal: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'.split(''),
|
||||
reverse: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'.split('')
|
||||
};
|
||||
|
||||
const filters = (order) => {
|
||||
// TODO: Refactor this with protobuf encoding
|
||||
switch (order) {
|
||||
case 'any,any,relevance':
|
||||
return 'EgIQAQ%3D%3D';
|
||||
@@ -325,4 +332,4 @@ const filters = (order) => {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { urls, oauth, oauth_reqopts, default_headers, innertube_request_opts, video_details_reqbody, stream_headers, formatVideoData, filters };
|
||||
module.exports = { urls, oauth, oauth_reqopts, default_headers, innertube_request_opts, video_details_reqbody, stream_headers, formatVideoData, base64_alphabet, filters };
|
||||
181
lib/Innertube.js
181
lib/Innertube.js
@@ -5,7 +5,9 @@ const Stream = require('stream');
|
||||
const OAuth = require('./OAuth');
|
||||
const Utils = require('./Utils');
|
||||
const Player = require('./Player');
|
||||
const NToken = require('./NToken');
|
||||
const Actions = require('./Actions');
|
||||
const Livechat = require('./Livechat');
|
||||
const Constants = require('./Constants');
|
||||
const SigDecipher = require('./SigDecipher');
|
||||
const EventEmitter = require('events');
|
||||
@@ -13,7 +15,7 @@ const TimeToSeconds = require('time-to-seconds');
|
||||
const CancelToken = Axios.CancelToken;
|
||||
|
||||
class Innertube extends EventEmitter {
|
||||
constructor(cookie, sign_in) {
|
||||
constructor(cookie) {
|
||||
super();
|
||||
this.cookie = cookie || '';
|
||||
return this.init();
|
||||
@@ -90,6 +92,7 @@ class Innertube extends EventEmitter {
|
||||
}
|
||||
|
||||
async search(query, options = { period: 'any', order: 'relevance', duration: 'any' }) {
|
||||
if (!query) throw new Error('No query was provided');
|
||||
if (!this.initialized) throw new Error('Missing Innertube data.');
|
||||
|
||||
const yt_response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/search${this.logged_in && this.cookie.length < 1 ? '' : `?key=${this.key}`}`, JSON.stringify({ context: this.context, params: Constants.filters(options.period + ',' + options.duration + ',' + options.order), query }), Constants.innertube_request_opts({ session: this })).catch((error) => error);
|
||||
@@ -134,23 +137,124 @@ class Innertube extends EventEmitter {
|
||||
}
|
||||
|
||||
async getDetails(id) {
|
||||
if (!id) return { error: 'Missing video id' };
|
||||
|
||||
const data = await this.requestVideoInfo(id, false);
|
||||
const video_data = Constants.formatVideoData(data, this, false);
|
||||
|
||||
video_data.like = like => Actions.likeVideo(this, id);
|
||||
video_data.dislike = dislike => Actions.dislikeVideo(this, id);
|
||||
video_data.removeLike = remove_like => Actions.removeLike(this, id);
|
||||
video_data.subscribe = subscribe => Actions.subscribe(this, id, video_data.metadata.channel_id);
|
||||
video_data.unsubscribe = unsubscribe => Actions.unsubscribe(this, id, video_data.metadata.channel_id);
|
||||
video_data.comment = comment => Actions.commentVideo(this, id, comment);
|
||||
if (video_data.metadata.is_live_content) {
|
||||
const data_continuation = await Actions.getContinuation(this, { video_id: id });
|
||||
if (!data_continuation.data.contents.twoColumnWatchNextResults.conversationBar) return;
|
||||
video_data.getLivechat = () => new Livechat(this, data_continuation.data.contents.twoColumnWatchNextResults.conversationBar.liveChatRenderer.continuations[0].reloadContinuationData.continuation, video_data.metadata.channel_id, id);
|
||||
} else {
|
||||
video_data.getLivechat = () => {};
|
||||
}
|
||||
|
||||
video_data.like = () => Actions.engage(this, 'like/like', { video_id: id });
|
||||
video_data.dislike = () => Actions.engage(this, 'like/dislike', { video_id: id });
|
||||
video_data.removeLike = () => Actions.engage(this, 'like/removelike', { video_id: id });
|
||||
video_data.subscribe = () => Actions.engage(this, 'subscription/subscribe', { video_id: id, channel_id: video_data.metadata.channel_id });
|
||||
video_data.unsubscribe = () => Actions.engage(this, 'subscription/unsubscribe', { video_id: id, channel_id: video_data.metadata.channel_id });
|
||||
video_data.comment = text => Actions.engage(this, 'comment/create_comment', { video_id: id, text });
|
||||
video_data.getComments = () => this.getComments(id);
|
||||
video_data.setNotificationPref = pref => Actions.notifications(this, 'modify_channel_preference', { channel_id: video_data.metadata.channel_id, pref: pref || 'NONE' });
|
||||
|
||||
return video_data;
|
||||
}
|
||||
|
||||
async getComments(video_id, token) {
|
||||
let comment_section_token;
|
||||
|
||||
if (!token) {
|
||||
const data_continuation = await Actions.getContinuation(this, { video_id });
|
||||
const item_section_renderer = data_continuation.data.contents.twoColumnWatchNextResults.results.results.contents.find((item) => item.itemSectionRenderer);
|
||||
comment_section_token = item_section_renderer.itemSectionRenderer.contents[0].continuationItemRenderer.continuationEndpoint.continuationCommand.token;
|
||||
}
|
||||
|
||||
const response = await Actions.getContinuation(this, { continuation_token: comment_section_token || token });
|
||||
if (!response.success) throw new Error('Could not fetch comment section');
|
||||
|
||||
const comments_section = { comments: [] };
|
||||
!token && (comments_section.comment_count = response.data.onResponseReceivedEndpoints[0].reloadContinuationItemsCommand.continuationItems && response.data.onResponseReceivedEndpoints[0].reloadContinuationItemsCommand.continuationItems[0].commentsHeaderRenderer.countText.runs[0].text || 'N/A');
|
||||
|
||||
let continuation_token;
|
||||
!token && (continuation_token = response.data.onResponseReceivedEndpoints[1].reloadContinuationItemsCommand.continuationItems.find((item) => item.continuationItemRenderer).continuationItemRenderer.continuationEndpoint.continuationCommand.token) ||
|
||||
(continuation_token = response.data.onResponseReceivedEndpoints[0].appendContinuationItemsAction.continuationItems.find((item) => item.continuationItemRenderer).continuationItemRenderer.continuationEndpoint.continuationCommand.token);
|
||||
|
||||
comments_section.getContinuation = () => this.getComments(video_id, continuation_token);
|
||||
|
||||
let contents;
|
||||
!token && (contents = response.data.onResponseReceivedEndpoints[1].reloadContinuationItemsCommand.continuationItems) ||
|
||||
(contents = response.data.onResponseReceivedEndpoints[0].appendContinuationItemsAction.continuationItems);
|
||||
|
||||
contents.forEach((thread) => {
|
||||
if (!thread.commentThreadRenderer) return;
|
||||
const comment = {
|
||||
text: thread.commentThreadRenderer.comment.commentRenderer.contentText.runs.map((t) => t.text).join(' '),
|
||||
author: {
|
||||
name: thread.commentThreadRenderer.comment.commentRenderer.authorText.simpleText,
|
||||
thumbnail: thread.commentThreadRenderer.comment.commentRenderer.authorThumbnail.thumbnails,
|
||||
channel_id: thread.commentThreadRenderer.comment.commentRenderer.authorEndpoint.browseEndpoint.browseId
|
||||
},
|
||||
metadata: {
|
||||
published: thread.commentThreadRenderer.comment.commentRenderer.publishedTimeText.runs[0].text,
|
||||
is_liked: thread.commentThreadRenderer.comment.commentRenderer.isLiked,
|
||||
is_channel_owner: thread.commentThreadRenderer.comment.commentRenderer.authorIsChannelOwner,
|
||||
like_count: thread.commentThreadRenderer.comment.commentRenderer.voteCount.simpleText,
|
||||
reply_count: thread.commentThreadRenderer.comment.commentRenderer.replyCount || 0,
|
||||
id: thread.commentThreadRenderer.comment.commentRenderer.commentId,
|
||||
}
|
||||
};
|
||||
comments_section.comments.push(comment);
|
||||
});
|
||||
|
||||
return comments_section;
|
||||
}
|
||||
|
||||
async getSubscriptionsFeed() {
|
||||
const response = await Actions.browse(this, 'subscriptions_feed');
|
||||
if (!response.success) throw new Error('Could not fetch subscriptions feed');
|
||||
|
||||
const contents = response.data.contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents;
|
||||
const subscriptions_feed = {};
|
||||
|
||||
contents.forEach((section) => {
|
||||
if (!section.itemSectionRenderer) return;
|
||||
|
||||
const section_contents = section.itemSectionRenderer.contents[0];
|
||||
const section_items = section_contents.shelfRenderer.content.gridRenderer.items;
|
||||
|
||||
const key = section_contents.shelfRenderer.title.runs[0].text;
|
||||
subscriptions_feed[key.toLowerCase().replace(/ +/g, '_')] = [];
|
||||
|
||||
section_items.forEach((item) => {
|
||||
const content = {
|
||||
title: item.gridVideoRenderer.title.runs.map((run) => run.text).join(' '),
|
||||
id: item.gridVideoRenderer.videoId,
|
||||
channel: item.gridVideoRenderer.shortBylineText && item.gridVideoRenderer.shortBylineText.runs[0].text || 'N/A',
|
||||
metadata: {
|
||||
view_count: item.gridVideoRenderer.viewCountText && item.gridVideoRenderer.viewCountText.simpleText || 'N/A',
|
||||
thumbnail: item.gridVideoRenderer.thumbnail && item.gridVideoRenderer.thumbnail.thumbnails || [],
|
||||
published: item.gridVideoRenderer.publishedTimeText && item.gridVideoRenderer.publishedTimeText.simpleText || 'N/A',
|
||||
badges: item.gridVideoRenderer.badges && item.gridVideoRenderer.badges.map((badge) => badge.metadataBadgeRenderer.label) || 'N/A',
|
||||
owner_badges: item.gridVideoRenderer.ownerBadges && item.gridVideoRenderer.ownerBadges.map((badge) => badge.metadataBadgeRenderer.tooltip) || 'N/A'
|
||||
}
|
||||
};
|
||||
|
||||
subscriptions_feed[key.toLowerCase().replace(/ +/g, '_')].push(content);
|
||||
});
|
||||
});
|
||||
|
||||
return subscriptions_feed;
|
||||
}
|
||||
|
||||
async getNotifications() {
|
||||
const response = await Actions.getNotifications(this);
|
||||
const contents = response.data.actions[0].openPopupAction.popup.multiPageMenuRenderer.sections[0].multiPageMenuNotificationSectionRenderer.items;
|
||||
return contents.map((notification) => {
|
||||
const response = await Actions.notifications(this, 'get_notification_menu');
|
||||
if (!response.success) throw new Error('Could not fetch notifications');
|
||||
|
||||
const contents = response.data.actions[0].openPopupAction.popup.multiPageMenuRenderer.sections[0];
|
||||
if (!contents.multiPageMenuNotificationSectionRenderer) return { error: 'You don\'t have any notification.' };
|
||||
return contents.multiPageMenuNotificationSectionRenderer.items.map((notification) => {
|
||||
if (!notification.notificationRenderer) return;
|
||||
notification = notification.notificationRenderer;
|
||||
return {
|
||||
@@ -159,17 +263,23 @@ class Innertube extends EventEmitter {
|
||||
channel_name: notification.contextualMenu.menuRenderer.items[1].menuServiceItemRenderer.text.runs[1].text,
|
||||
channel_thumbnail: notification.thumbnail.thumbnails[0],
|
||||
video_thumbnail: notification.videoThumbnail.thumbnails[0],
|
||||
video_url: 'https://youtu.be/' + notification.navigationEndpoint.watchEndpoint.videoId,
|
||||
video_url: `https://youtu.be/${notification.navigationEndpoint.watchEndpoint.videoId}`,
|
||||
read: notification.read,
|
||||
notification_id: notification.notificationId,
|
||||
};
|
||||
}).filter((notification_block) => notification_block);
|
||||
}
|
||||
|
||||
async getUnseenNotificationsCount() {
|
||||
const response = await Actions.notifications(this, 'get_unseen_count');
|
||||
if (!response.success) throw new Error('Could not fetch unseen notifications count');
|
||||
return response.data.unseenCount;
|
||||
}
|
||||
|
||||
async requestVideoInfo(id, desktop) {
|
||||
let response;
|
||||
if (!desktop) {
|
||||
response = await Axios.get(Constants.urls.YT_WATCH_PAGE + '?v=' + id + 't=8s&pbj=1&bpctr=9999999999&has_verified=1&', Constants.innertube_request_opts({ session: this, id, desktop: false })).catch((error) => error);
|
||||
response = await Axios.get(`${Constants.urls.YT_WATCH_PAGE}?v=${id}&t=8s&pbj=1`, Constants.innertube_request_opts({ session: this, id, desktop: false })).catch((error) => error);
|
||||
} else {
|
||||
response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/player${this.logged_in && this.cookie.length < 1 ? '' : `?key=${this.key}`}`, JSON.stringify(Constants.video_details_reqbody(id, this.sts, this.context)), Constants.innertube_request_opts({ session: this, id, desktop: true })).catch((error) => error);
|
||||
}
|
||||
@@ -178,6 +288,8 @@ class Innertube extends EventEmitter {
|
||||
}
|
||||
|
||||
download(id, options = {}) {
|
||||
if (!id) throw new Error('Missing video id');
|
||||
|
||||
options.quality = options.quality || '360p';
|
||||
options.type = options.type || 'videoandaudio';
|
||||
options.format = options.format || 'mp4';
|
||||
@@ -197,12 +309,12 @@ class Innertube extends EventEmitter {
|
||||
format.url = format.url || format.signatureCipher || format.cipher;
|
||||
|
||||
if (format.signatureCipher || format.cipher) {
|
||||
format.url = new SigDecipher(format.url, this.context.client.clientVersion, this.player.sig_decipher_sc, this.player.encodeN).decipher();
|
||||
format.url = new SigDecipher(format.url, this.context.client.clientVersion, this.player).decipher();
|
||||
} else {
|
||||
const url_components = new URL(format.url);
|
||||
url_components.searchParams.set('cver', this.context.client.clientVersion);
|
||||
url_components.searchParams.set('ratebypass', 'yes');
|
||||
url_components.searchParams.set('n', this.player.encodeN(url_components.searchParams.get('n')));
|
||||
url_components.searchParams.set('n', new NToken(this.player.ntoken_sc).transform(url_components.searchParams.get('n')));
|
||||
format.url = url_components.toString();
|
||||
}
|
||||
|
||||
@@ -262,7 +374,12 @@ class Innertube extends EventEmitter {
|
||||
}
|
||||
|
||||
if (options.type == 'videoandaudio') {
|
||||
const response = await Axios.get(selected_format.url, { cancelToken: new CancelToken(function executor(c) { cancel = c; }), responseType: 'stream', reponseEncoding: 'binary', headers: Constants.stream_headers() }).catch((error) => error);
|
||||
const response = await Axios.get(selected_format.url, {
|
||||
responseType: 'stream',
|
||||
cancelToken: new CancelToken(function executor(c) { cancel = c; }),
|
||||
headers: Constants.stream_headers()
|
||||
}).catch((error) => error);
|
||||
|
||||
if (response instanceof Error) {
|
||||
stream.emit('error', { message: response.message, type: 'REQUEST_FAILED' });
|
||||
return stream;
|
||||
@@ -286,18 +403,26 @@ class Innertube extends EventEmitter {
|
||||
}
|
||||
});
|
||||
|
||||
response.data.pipe(stream, true);
|
||||
response.data.pipe(stream, { end: true });
|
||||
} else {
|
||||
const chunk_size = 1048576 * 10; // 10MB
|
||||
|
||||
let chunk_start = 0;
|
||||
let chunk_end = chunk_size;
|
||||
let downloaded_size = 0;
|
||||
let end = false;
|
||||
|
||||
stream.emit('start');
|
||||
|
||||
const downloadChunk = async () => {
|
||||
const response = await Axios.get(selected_format.url, { cancelToken: new CancelToken(function executor(c) { cancel = c; }), responseType: 'stream', headers: Constants.stream_headers(`bytes=${chunk_start}-${chunk_end || ''}`) }).catch((error) => error);
|
||||
if (chunk_end >= selected_format.contentLength) end = true;
|
||||
|
||||
const response = await Axios.get(`${selected_format.url}&range=${chunk_start}-${chunk_end || ''}`, {
|
||||
responseType: 'stream',
|
||||
cancelToken: new CancelToken(function executor(c) { cancel = c; }),
|
||||
headers: Constants.stream_headers()
|
||||
}).catch((error) => error);
|
||||
|
||||
if (response instanceof Error) {
|
||||
stream.emit('error', { message: response.message, type: 'REQUEST_FAILED' });
|
||||
return stream;
|
||||
@@ -310,17 +435,6 @@ class Innertube extends EventEmitter {
|
||||
stream.emit('progress', { chunk_size: chunk.length, downloaded_size: (downloaded_size / 1024 / 1024).toFixed(2), percentage, size, raw_data: { chunk_size: chunk.length, downloaded: downloaded_size, size: response.headers['content-length'] } });
|
||||
});
|
||||
|
||||
response.data.on('end', () => {
|
||||
chunk_start = chunk_end + 1;
|
||||
chunk_end += chunk_size;
|
||||
|
||||
if (downloaded_size < selected_format.contentLength) {
|
||||
downloadChunk();
|
||||
} else {
|
||||
stream.emit('end');
|
||||
}
|
||||
});
|
||||
|
||||
response.data.on('error', (err) => {
|
||||
if (cancelled) {
|
||||
stream.emit('error', { message: 'The download was cancelled.', type: 'DOWNLOAD_CANCELLED' });
|
||||
@@ -329,7 +443,15 @@ class Innertube extends EventEmitter {
|
||||
}
|
||||
});
|
||||
|
||||
response.data.pipe(stream, { end: false });
|
||||
response.data.on('end', () => {
|
||||
if (!end) {
|
||||
chunk_start = chunk_end + 1;
|
||||
chunk_end += chunk_size;
|
||||
downloadChunk();
|
||||
}
|
||||
});
|
||||
|
||||
response.data.pipe(stream, { end });
|
||||
};
|
||||
downloadChunk();
|
||||
}
|
||||
@@ -339,6 +461,7 @@ class Innertube extends EventEmitter {
|
||||
cancelled = true;
|
||||
cancel();
|
||||
};
|
||||
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
132
lib/Livechat.js
Normal file
132
lib/Livechat.js
Normal file
@@ -0,0 +1,132 @@
|
||||
'use strict';
|
||||
|
||||
const Axios = require('axios');
|
||||
const Actions = require('./Actions');
|
||||
const Constants = require('./Constants');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
class Livechat extends EventEmitter {
|
||||
constructor(session, token, channel_id, video_id) {
|
||||
super(session);
|
||||
this.ctoken = token;
|
||||
this.session = session;
|
||||
this.video_id = video_id;
|
||||
this.channel_id = channel_id;
|
||||
|
||||
this.message_queue = [];
|
||||
this.id_cache = [];
|
||||
|
||||
this.poll_intervals_ms = 1000;
|
||||
this.running = true;
|
||||
|
||||
this.poll();
|
||||
}
|
||||
|
||||
enqueueActionGroup(group) {
|
||||
group.forEach((action) => {
|
||||
if (!action.addChatItemAction) return; //TODO: handle different action types
|
||||
const message_content = action.addChatItemAction.item.liveChatTextMessageRenderer;
|
||||
if (!message_content) return;
|
||||
|
||||
const message = {
|
||||
text: message_content.message.runs.map((item) => item.text).join(' '),
|
||||
author: {
|
||||
name: message_content.authorName && message_content.authorName.simpleText || 'N/',
|
||||
channel_id: message_content.authorExternalChannelId,
|
||||
profile_picture: message_content.authorPhoto.thumbnails
|
||||
},
|
||||
timestamp: message_content.timestampUsec,
|
||||
id: message_content.id
|
||||
};
|
||||
|
||||
this.message_queue.push(message);
|
||||
});
|
||||
}
|
||||
|
||||
async poll() {
|
||||
if (!this.running) return;
|
||||
|
||||
let data;
|
||||
|
||||
data = { context: this.session.context, continuation: this.ctoken };
|
||||
const livechat = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/live_chat/get_live_chat${this.session.logged_in && this.session.cookie.length < 1 ? '' : `?key=${this.session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session: this.session, data, desktop: true }));
|
||||
if (livechat instanceof Error) throw new Error(`Error polling livechat: ${livechat.message}`);
|
||||
|
||||
const continuation_contents = livechat.data.continuationContents;
|
||||
const action_group = continuation_contents.liveChatContinuation.actions;
|
||||
this.enqueueActionGroup(action_group);
|
||||
|
||||
// Why don't we just emit the message directly? Well, enqueueing the messages is necessary so they are not emitted in a “messy” way, funny enough that's exactly how YouTube does it in its livechat js player.
|
||||
this.message_queue.forEach((message, index) => {
|
||||
if (this.id_cache.includes(message.id)) return;
|
||||
setTimeout(() => this.emit('chat-update', message), message.timestamp / 1000 - new Date().getTime());
|
||||
this.id_cache.push(message.id);
|
||||
});
|
||||
|
||||
this.message_queue = [];
|
||||
|
||||
data = { context: this.session.context, videoId: this.video_id };
|
||||
if (this.metadata_ctoken) data.continuation = this.metadata_ctoken;
|
||||
|
||||
const updated_metadata = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/updated_metadata${this.session.logged_in && this.session.cookie.length < 1 ? '' : `?key=${this.session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session: this.session, data, desktop: true }));
|
||||
if (updated_metadata instanceof Error) throw new Error(`Error polling updated metadata: ${updated_metadata.message}`);
|
||||
this.metadata_ctoken = updated_metadata.data.continuation.timedContinuationData.continuation;
|
||||
|
||||
const metadata = updated_metadata.data.actions;
|
||||
this.emit('update-metadata', {
|
||||
likes: metadata[1].updateToggleButtonTextAction.defaultText.simpleText,
|
||||
dislikes: metadata[2].updateToggleButtonTextAction.defaultText.simpleText,
|
||||
view_count: {
|
||||
simple_text: metadata[0].updateViewershipAction.viewCount.videoViewCountRenderer.viewCount.simpleText,
|
||||
short_view_count: metadata[0].updateViewershipAction.viewCount.videoViewCountRenderer.extraShortViewCount.simpleText
|
||||
}
|
||||
});
|
||||
|
||||
this.livechat_poller = setTimeout(async () => await this.poll(), this.poll_intervals_ms);
|
||||
}
|
||||
|
||||
async sendMessage(text) {
|
||||
const message = await Actions.livechat(this.session, 'live_chat/send_message', { text, channel_id: this.channel_id, video_id: this.video_id });
|
||||
if (!message.success) return message;
|
||||
|
||||
const deleteMessage = async () => {
|
||||
const menu = await Actions.livechat(this.session, 'live_chat/get_item_context_menu', { params: { params: message.data.actions[0].addChatItemAction.item.liveChatTextMessageRenderer.contextMenuEndpoint.liveChatItemContextMenuEndpoint.params, pbj: 1 } });
|
||||
if (!menu.success) return menu;
|
||||
|
||||
const chat_item_menu = menu.data.liveChatItemContextMenuSupportedRenderers.menuRenderer.items[0];
|
||||
|
||||
const cmd = await Actions.livechat(this.session, 'live_chat/moderate', { cmd_params: chat_item_menu.menuServiceItemRenderer.serviceEndpoint.moderateLiveChatEndpoint.params });
|
||||
if (!cmd.success) return cmd;
|
||||
|
||||
return { success: true, status_code: cmd.status_code };
|
||||
};
|
||||
|
||||
return {
|
||||
success: true,
|
||||
status_code: message.status_code,
|
||||
deleteMessage,
|
||||
message_data: {
|
||||
text: message.data.actions[0].addChatItemAction.item.liveChatTextMessageRenderer.message.runs.map((item) => item.text).join(' '),
|
||||
author: {
|
||||
name: message.data.actions[0].addChatItemAction.item.liveChatTextMessageRenderer.authorName && message.data.actions[0].addChatItemAction.item.liveChatTextMessageRenderer.authorName.simpleText || 'N/',
|
||||
channel_id: message.data.actions[0].addChatItemAction.item.liveChatTextMessageRenderer.authorExternalChannelId,
|
||||
profile_picture: message.data.actions[0].addChatItemAction.item.liveChatTextMessageRenderer.authorPhoto.thumbnails
|
||||
},
|
||||
timestamp: message.data.actions[0].addChatItemAction.item.liveChatTextMessageRenderer.timestampUsec,
|
||||
id: message.data.actions[0].addChatItemAction.item.liveChatTextMessageRenderer.id
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async blockUser(msg_params) {
|
||||
/* TODO: Implement this */
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.running = false;
|
||||
clearTimeout(this.livechat_poller);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Livechat;
|
||||
129
lib/NToken.js
Normal file
129
lib/NToken.js
Normal file
@@ -0,0 +1,129 @@
|
||||
'use strict';
|
||||
|
||||
const Utils = require('./Utils');
|
||||
const Constants = require('./Constants');
|
||||
|
||||
class NToken {
|
||||
constructor(raw_code) {
|
||||
this.raw_code = raw_code;
|
||||
this.null_placeholder_regex = /c\[(.*?)\]=c/g;
|
||||
this.transformation_args_regex = /c\[(.*?)\]\((.+?)\)/g;
|
||||
}
|
||||
|
||||
transform(n) {
|
||||
let n_token = n.split('');
|
||||
let transformations = this.getTransformationData(this.raw_code);
|
||||
|
||||
// Identifies the necessary transformation functions and emulates them accordingly.
|
||||
transformations = transformations.map((el) => {
|
||||
if (el != null && typeof el != 'number') {
|
||||
const is_reverse_base64 = el.includes('case 65:');
|
||||
if (el.includes('function(d){for(var')) {
|
||||
el = (arr) => this.pushSplice(arr);
|
||||
} else if (el.includes('d.push(e)')) {
|
||||
el = (arr, item) => this.push(arr, item);
|
||||
} else if (el.includes('d.reverse()')) {
|
||||
el = (arr) => this.reverse(arr);
|
||||
} else if (el.includes('d.length;d.splice(e,1)')) {
|
||||
el = (arr, index) => this.spliceOnce(arr, index);
|
||||
} else if (el.includes('d[0])[0])')) {
|
||||
el = (arr, index) => this.spliceTwice(arr, index);
|
||||
} else if (el.includes('reverse().forEach')) {
|
||||
el = (arr, index) => this.spliceReverseUnshift(arr, index);
|
||||
} else if (el.includes('f=d[0];d[0]')) {
|
||||
el = (arr, index) => this.swapFirstItem(arr, index);
|
||||
} else if (el.includes('unshift(d.pop())')) {
|
||||
el = (arr, index) => this.unshiftPop(arr, index);
|
||||
} else if (el.includes('switch')) {
|
||||
el = (arr, e) => this.translateAB(arr, e, is_reverse_base64);
|
||||
} else if (el === 'b') {
|
||||
el = n_token;
|
||||
}
|
||||
}
|
||||
return el;
|
||||
});
|
||||
|
||||
// Fills the null placeholders with a copy of the transformations array.
|
||||
let null_placeholder_positions = [...this.raw_code.matchAll(this.null_placeholder_regex)].map((item) => parseInt(item[1]));
|
||||
null_placeholder_positions.forEach((pos) => transformations[pos] = transformations);
|
||||
|
||||
// Parses and emulates calls to functions of the transformations array.
|
||||
let transformation_args = [...Utils.getStringBetweenStrings(this.raw_code.replace(/\n/g, ''), 'try{', '}catch').matchAll(this.transformation_args_regex)].map((params) => ({ index: params[1], params: params[2] }));
|
||||
transformation_args.forEach((data) => {
|
||||
const index = data.index;
|
||||
const param_index = data.params.split(',').map((param) => param.match(/c\[(.*?)\]/)[1]);
|
||||
transformations[index](transformations[param_index[0]], transformations[param_index[1]]);
|
||||
});
|
||||
|
||||
return n_token.join('');
|
||||
}
|
||||
|
||||
getTransformationData() {
|
||||
let transformation_data = '[' + Utils.getStringBetweenStrings(this.raw_code, 'c=[', '];c') + ']';
|
||||
transformation_data = transformation_data
|
||||
.replace(/function\(d,e\)/g, '"function(d,e)')
|
||||
.replace(/function\(d\)/g, '"function(d)')
|
||||
.replace(/,b,/g, ',"b",')
|
||||
.replace(/,b/g, ',"b"')
|
||||
.replace(/b,/g, '"b",')
|
||||
.replace(/b]/g, '"b"]')
|
||||
.replace(/},/g, '}",')
|
||||
.replace(/""/g, '')
|
||||
.replace(/length]\)}"/g, 'length])}');
|
||||
|
||||
return JSON.parse(transformation_data);
|
||||
}
|
||||
|
||||
translateAB(arr, e, is_reverse_base64) {
|
||||
let characters = is_reverse_base64 && Constants.base64_alphabet.reverse || Constants.base64_alphabet.normal;
|
||||
arr.forEach(function(char, index, loc) {
|
||||
this.push(loc[index] = characters[(characters.indexOf(char) - characters.indexOf(this[index]) + 64) % characters.length]);
|
||||
}, e.split(''));
|
||||
}
|
||||
|
||||
unshiftPop(arr, index) {
|
||||
index = (index % arr.length + arr.length) % arr.length;
|
||||
for (; index--;) {
|
||||
arr.unshift(arr.pop());
|
||||
}
|
||||
}
|
||||
|
||||
swapFirstItem(arr, index) {
|
||||
let oldValue = arr[0];
|
||||
index = (index % arr.length + arr.length) % arr.length;
|
||||
arr[0] = arr[index];
|
||||
arr[index] = oldValue;
|
||||
}
|
||||
|
||||
spliceReverseUnshift(arr, index) {
|
||||
index = (index % arr.length + arr.length) % arr.length;
|
||||
arr.splice(-index).reverse().forEach(function(f) {
|
||||
arr.unshift(f);
|
||||
});
|
||||
}
|
||||
|
||||
spliceOnce(arr, index) {
|
||||
index = (index % arr.length + arr.length) % arr.length;
|
||||
arr.splice(index, 1);
|
||||
}
|
||||
|
||||
spliceTwice(arr, index) {
|
||||
index = (index % arr.length + arr.length) % arr.length;
|
||||
arr.splice(0, 1, arr.splice(index, 1, arr[0])[0]);
|
||||
}
|
||||
|
||||
pushSplice(arr) {
|
||||
for (let index = arr.length; index;)
|
||||
arr.push(arr.splice(--index, 1)[0]);
|
||||
}
|
||||
|
||||
push(arr, item) {
|
||||
arr.push(item);
|
||||
}
|
||||
|
||||
reverse(arr) {
|
||||
arr.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NToken;
|
||||
78
lib/OAuth.js
78
lib/OAuth.js
@@ -7,49 +7,49 @@ const EventEmitter = require('events');
|
||||
const Uuid = require("uuid");
|
||||
|
||||
class OAuth extends EventEmitter {
|
||||
constructor (creds) {
|
||||
constructor(creds) {
|
||||
super();
|
||||
// Default interval between requests when waiting for authorization.
|
||||
this.refresh_interval = 5;
|
||||
|
||||
|
||||
// OAuth URLs:
|
||||
this.oauth_code_url = `${Constants.urls.YT_BASE_URL}/o/oauth2/device/code`;
|
||||
this.oauth_token_url = `${Constants.urls.YT_BASE_URL}/o/oauth2/token`;
|
||||
|
||||
|
||||
// Used to check whether an access token is valid or not.
|
||||
this.guide_url = `${Constants.urls.YT_BASE_URL}/youtubei/v1/guide`;
|
||||
|
||||
|
||||
// These are always the same, so we shouldn't have any problems for now.
|
||||
this.model_name = Constants.oauth.model_name;
|
||||
this.grant_type = Constants.oauth.grant_type;
|
||||
this.scope = Constants.oauth.scope;
|
||||
|
||||
|
||||
// Script that contains important information such as client id and client secret.
|
||||
this.auth_script_regex = /<script id=\"base-js\" src=\"(.*?)\" nonce=".*?"><\/script>/;
|
||||
|
||||
|
||||
// Used to find the credentials inside the script.
|
||||
this.identity_regex = /var .+?=\"(?<id>.+?)\",[.|\s].?=\"(?<secret>.+?)\"/;
|
||||
|
||||
|
||||
if (creds.access_token != undefined && creds.refresh_token != undefined) return;
|
||||
this.requestAuthCode();
|
||||
}
|
||||
|
||||
async waitForAuth(device_code) {
|
||||
|
||||
waitForAuth(device_code) {
|
||||
const data = {
|
||||
client_id: this.client_id,
|
||||
client_secret: this.client_secret,
|
||||
code: device_code,
|
||||
grant_type: this.grant_type
|
||||
};
|
||||
|
||||
|
||||
setTimeout(async () => {
|
||||
const response = await Axios.post(this.oauth_token_url, JSON.stringify(data), Constants.oauth_reqopts).catch((error) => error);
|
||||
if (response instanceof Error)
|
||||
if (response instanceof Error)
|
||||
return this.emit('auth', {
|
||||
error: 'Could not get auth token.',
|
||||
status: 'FAILED'
|
||||
});
|
||||
|
||||
|
||||
if (response.data.error) {
|
||||
switch (response.data.error) {
|
||||
case 'slow_down':
|
||||
@@ -73,7 +73,7 @@ class OAuth extends EventEmitter {
|
||||
}
|
||||
} else {
|
||||
this.emit('auth', {
|
||||
access_token: response.data.access_token,
|
||||
access_token: response.data.access_token,
|
||||
refresh_token: response.data.refresh_token,
|
||||
token_type: response.data.token_type,
|
||||
expires: response.data.expires_in,
|
||||
@@ -83,86 +83,86 @@ class OAuth extends EventEmitter {
|
||||
}
|
||||
}, 1000 * this.refresh_interval);
|
||||
}
|
||||
|
||||
|
||||
async requestAuthCode() {
|
||||
const identity = await this.getClientIdentity();
|
||||
this.client_id = identity.id;
|
||||
this.client_secret = identity.secret;
|
||||
|
||||
|
||||
const data = {
|
||||
client_id: this.client_id,
|
||||
scope: this.scope,
|
||||
device_id : Uuid.v4(),
|
||||
device_id: Uuid.v4(),
|
||||
model_name: this.model_name
|
||||
};
|
||||
|
||||
|
||||
const response = await Axios.post(this.oauth_code_url, JSON.stringify(data), Constants.oauth_reqopts).catch((error) => error);
|
||||
if (response instanceof Error)
|
||||
if (response instanceof Error)
|
||||
return this.emit('auth', {
|
||||
error: 'Could not get auth code.',
|
||||
status: 'FAILED'
|
||||
});
|
||||
|
||||
|
||||
this.emit('auth', {
|
||||
code: response.data.user_code,
|
||||
code: response.data.user_code,
|
||||
status: 'AUTHORIZATION_PENDING',
|
||||
expires_in: response.data.expires_in,
|
||||
expires_in: response.data.expires_in,
|
||||
verification_url: response.data.verification_url
|
||||
});
|
||||
|
||||
|
||||
this.refresh_interval = response.data.interval;
|
||||
|
||||
|
||||
// Keeps requesting at a specific rate until the authorization is granted or denied.
|
||||
this.waitForAuth(response.data.device_code);
|
||||
}
|
||||
|
||||
|
||||
async getClientIdentity() {
|
||||
// The first request is made to get the auth script url, hard-coding it isn't viable as it changes overtime.
|
||||
const yttv_response = await Axios.get(`${Constants.urls.YT_BASE_URL}/tv`, Constants.oauth_reqopts).catch((error) => error);
|
||||
if (yttv_response instanceof Error) throw new Error(`Could not get identify: ${yttv_response.message}`);
|
||||
|
||||
|
||||
// Here we get the script and extract the necessary data to proceed with the auth flow.
|
||||
const url_body = this.auth_script_regex.exec(yttv_response.data)[1];
|
||||
const script_url = `${Constants.urls.YT_BASE_URL}/${url_body}`;
|
||||
const response = await Axios.get(script_url, Constants.default_headers).catch((error) => error);
|
||||
if (response instanceof Error) throw new Error(`Could not fetch data from auth script: ${response.message}`);
|
||||
|
||||
const identify_function = Utils.getStringBetweenStrings(response.data, '=function(){var a=window.environment', '(function()');
|
||||
const client_identity = identify_function.match(this.identity_regex).groups;
|
||||
|
||||
const identity_function = Utils.getStringBetweenStrings(response.data, '=function(){var a=window.environment', '(function()');
|
||||
const client_identity = identity_function.match(this.identity_regex).groups;
|
||||
return client_identity;
|
||||
}
|
||||
|
||||
async refreshAccessToken (refresh_token) {
|
||||
|
||||
async refreshAccessToken(refresh_token) {
|
||||
const identity = await this.getClientIdentity();
|
||||
|
||||
|
||||
const data = {
|
||||
client_id: identity.id,
|
||||
client_secret: identity.secret,
|
||||
refresh_token,
|
||||
grant_type : 'refresh_token',
|
||||
grant_type: 'refresh_token',
|
||||
};
|
||||
|
||||
|
||||
const response = await Axios.post(this.oauth_token_url, JSON.stringify(data), Constants.oauth_reqopts).catch((error) => error);
|
||||
if (response instanceof Error)
|
||||
if (response instanceof Error)
|
||||
return this.emit('refresh-token', {
|
||||
error: 'Could not refresh token.',
|
||||
status: 'FAILED'
|
||||
});
|
||||
|
||||
|
||||
this.emit('refresh-token', {
|
||||
access_token: response.data.access_token,
|
||||
access_token: response.data.access_token,
|
||||
token_type: response.data.token_type,
|
||||
expires: response.data.expires_in,
|
||||
scope: response.data.scope,
|
||||
status: 'SUCCESS'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async checkTokenValidity(access_token, session) {
|
||||
let headers = Constants.innertube_request_opts({ session }).headers;
|
||||
headers.authorization = `Bearer ${access_token}`;
|
||||
|
||||
const response = await Axios.post(this.guide_url, JSON.stringify({ context : session.context }), { headers }).catch((error) => error);
|
||||
|
||||
const response = await Axios.post(this.guide_url, JSON.stringify({ context: session.context }), { headers }).catch((error) => error);
|
||||
if (response instanceof Error) return 'INVALID';
|
||||
return 'VALID';
|
||||
}
|
||||
|
||||
@@ -13,16 +13,16 @@ class Player {
|
||||
}
|
||||
|
||||
async init() {
|
||||
if (fs.existsSync(this.tmp_cache_dir + '/' + this.player_name + '.js')) {
|
||||
const player_data = fs.readFileSync(this.tmp_cache_dir + '/' + this.player_name + '.js').toString();
|
||||
if (fs.existsSync(`${this.tmp_cache_dir}/${this.player_name}.js`)) {
|
||||
const player_data = fs.readFileSync(`${this.tmp_cache_dir}/${this.player_name}.js`).toString();
|
||||
this.getSigDecipherCode(player_data);
|
||||
this.getNEncoder(player_data);
|
||||
} else {
|
||||
const response = await Axios.get(Constants.urls.YT_BASE_URL + this.session.player_url, { path: this.session.playerUrl, headers: { 'content-type': 'text/javascript', 'user-agent': Utils.getRandomUserAgent('desktop').userAgent } }).catch((error) => error);
|
||||
const response = await Axios.get(`${Constants.urls.YT_BASE_URL}${this.session.player_url}`, { path: this.session.playerUrl, headers: { 'content-type': 'text/javascript', 'user-agent': Utils.getRandomUserAgent('desktop').userAgent } }).catch((error) => error);
|
||||
if (response instanceof Error) throw new Error('Could not get player data: ' + response.message);
|
||||
|
||||
fs.mkdirSync(this.tmp_cache_dir, { recursive: true });
|
||||
fs.writeFileSync(this.tmp_cache_dir + '/' + this.player_name + '.js', response.data);
|
||||
fs.writeFileSync(`${this.tmp_cache_dir}/${this.player_name}.js`, response.data);
|
||||
|
||||
this.getSigDecipherCode(response.data);
|
||||
this.getNEncoder(response.data);
|
||||
@@ -30,14 +30,13 @@ class Player {
|
||||
}
|
||||
|
||||
getSigDecipherCode(data) {
|
||||
const actions_algorithm_code = Utils.getStringBetweenStrings(data, 'this.audioTracks};var', '};');
|
||||
const actions_sequence_code = Utils.getStringBetweenStrings(data, 'function(a){a=a.split("")', 'return a.join("")}');
|
||||
this.sig_decipher_sc = actions_algorithm_code + actions_sequence_code;
|
||||
const manipulation_algorithm_code = Utils.getStringBetweenStrings(data, 'this.audioTracks};var', '};');
|
||||
const manipulation_sequence_code = Utils.getStringBetweenStrings(data, 'function(a){a=a.split("")', 'return a.join("")}');
|
||||
this.sig_decipher_sc = manipulation_algorithm_code + manipulation_sequence_code;
|
||||
}
|
||||
|
||||
getNEncoder(data) {
|
||||
const raw_code = 'var b=a.split("")' + Utils.getStringBetweenStrings(data, 'b=a.split("")', '}return b.join("")}') + '} return b.join("");';
|
||||
this.encodeN = Utils.createFunction('a', raw_code);
|
||||
this.ntoken_sc = 'var b=a.split("")' + Utils.getStringBetweenStrings(data, 'b=a.split("")', '}return b.join("")}') + '} return b.join("");';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const NToken = require('./NToken');
|
||||
const QueryString = require('querystring');
|
||||
|
||||
class SigDecipher {
|
||||
constructor(url, cver, func_code, encode_n) {
|
||||
constructor(url, cver, player) {
|
||||
this.url = url;
|
||||
this.cver = cver;
|
||||
this.func_code = func_code;
|
||||
this.encode_n = encode_n;
|
||||
this.player = player;
|
||||
this.func_regex = /(.{2}):function\(.*?\){(.*?)}/g;
|
||||
this.actions_regex = /;.{2}\.(.{2})\(.*?,(.*?)\)/g;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class SigDecipher {
|
||||
let actions;
|
||||
let signature = args.s.split('');
|
||||
|
||||
while ((actions = this.actions_regex.exec(this.func_code)) !== null) {
|
||||
while ((actions = this.actions_regex.exec(this.player.sig_decipher_sc)) !== null) {
|
||||
switch (actions[1]) {
|
||||
case functions[0]:
|
||||
reverse(signature, actions[2]);
|
||||
@@ -49,10 +49,11 @@ class SigDecipher {
|
||||
}
|
||||
|
||||
const url_components = new URL(args.url);
|
||||
|
||||
args.sp !== undefined ? url_components.searchParams.set(args.sp, signature.join('')) : url_components.searchParams.set('signature', signature.join(''));
|
||||
url_components.searchParams.set('cver', this.cver);
|
||||
url_components.searchParams.set('ratebypass', 'yes');
|
||||
url_components.searchParams.set('n', this.encode_n(url_components.searchParams.get('n')));
|
||||
url_components.searchParams.set('n', new NToken(this.player.ntoken_sc).transform(url_components.searchParams.get('n')));
|
||||
return url_components.toString();
|
||||
}
|
||||
|
||||
@@ -60,7 +61,7 @@ class SigDecipher {
|
||||
let func;
|
||||
let func_name = [];
|
||||
|
||||
while ((func = this.func_regex.exec(this.func_code)) !== null) {
|
||||
while ((func = this.func_regex.exec(this.player.sig_decipher_sc)) !== null) {
|
||||
if (func[0].includes('reverse()')) {
|
||||
func_name[0] = func[1];
|
||||
} else if (func[0].includes('splice')) {
|
||||
|
||||
50
lib/Utils.js
50
lib/Utils.js
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Fs = require('fs');
|
||||
const Proto = require('protons');
|
||||
const Crypto = require('crypto');
|
||||
const UserAgent = require('user-agents');
|
||||
|
||||
@@ -35,12 +37,50 @@ function escapeStringRegexp(string) {
|
||||
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
||||
}
|
||||
|
||||
function createFunction(input, raw_code) { // I hate this
|
||||
return new Function(input, raw_code);
|
||||
function encodeNotificationPref(channel_id, index) {
|
||||
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
|
||||
|
||||
const buf = youtube_proto.NotificationPreferences.encode({
|
||||
channel_id,
|
||||
pref_id: {
|
||||
index
|
||||
},
|
||||
number_0: 0,
|
||||
number_1: 4
|
||||
});
|
||||
|
||||
return encodeURIComponent(Buffer.from(buf).toString('base64'));
|
||||
}
|
||||
|
||||
function encodeId(id) {
|
||||
return encodeURI(new Buffer.from(`` + id + `*`).toString('base64').replace('==', '') + 'BQBw==');
|
||||
function generateMessageParams(channel_id, video_id) {
|
||||
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
|
||||
|
||||
const buf = youtube_proto.LiveMessageParams.encode({
|
||||
params: {
|
||||
ids: {
|
||||
channel_id,
|
||||
video_id
|
||||
}
|
||||
},
|
||||
number_0: 1,
|
||||
number_1: 4
|
||||
});
|
||||
|
||||
return Buffer.from(encodeURIComponent(Buffer.from(buf).toString('base64'))).toString('base64');
|
||||
}
|
||||
|
||||
module.exports = { getRandomUserAgent, generateSidAuth, getStringBetweenStrings, createFunction, encodeId };
|
||||
function generateCommentParams(video_id) {
|
||||
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
|
||||
|
||||
const buf = youtube_proto.CreateCommentParams.encode({
|
||||
video_id,
|
||||
params: {
|
||||
index: 0
|
||||
},
|
||||
number: 7
|
||||
});
|
||||
|
||||
return encodeURIComponent(Buffer.from(buf).toString('base64'));
|
||||
}
|
||||
|
||||
module.exports = { getRandomUserAgent, generateSidAuth, getStringBetweenStrings, generateMessageParams, generateCommentParams, encodeNotificationPref };
|
||||
34
lib/proto/youtube.proto
Normal file
34
lib/proto/youtube.proto
Normal file
@@ -0,0 +1,34 @@
|
||||
syntax = "proto2";
|
||||
package proto;
|
||||
|
||||
message NotificationPreferences {
|
||||
string channel_id = 1;
|
||||
message Preference {
|
||||
int32 index = 1;
|
||||
}
|
||||
Preference pref_id = 2;
|
||||
int32 number_0 = 3;
|
||||
int32 number_1 = 4;
|
||||
}
|
||||
|
||||
message LiveMessageParams {
|
||||
message Params {
|
||||
message Ids {
|
||||
string channel_id = 1;
|
||||
string video_id = 2;
|
||||
}
|
||||
Ids ids = 5;
|
||||
}
|
||||
Params params = 1;
|
||||
int32 number_0 = 2;
|
||||
int32 number_1 = 3;
|
||||
}
|
||||
|
||||
message CreateCommentParams {
|
||||
string video_id = 2;
|
||||
message Params {
|
||||
int32 index = 1;
|
||||
}
|
||||
Params params = 5;
|
||||
int32 number = 10;
|
||||
}
|
||||
101
package-lock.json
generated
101
package-lock.json
generated
@@ -1,15 +1,16 @@
|
||||
{
|
||||
"name": "youtubei.js",
|
||||
"version": "1.0.5",
|
||||
"version": "1.2.2",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "youtubei.js",
|
||||
"version": "1.0.5",
|
||||
"version": "1.2.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^0.21.4",
|
||||
"protons": "^2.0.3",
|
||||
"time-to-seconds": "^1.1.5",
|
||||
"user-agents": "^1.0.778",
|
||||
"uuid": "^8.3.2"
|
||||
@@ -76,6 +77,35 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
|
||||
},
|
||||
"node_modules/multiformats": {
|
||||
"version": "9.4.9",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.4.9.tgz",
|
||||
"integrity": "sha512-zA84TTJcRfRMpjvYqy63piBbSEdqlIGqNNSpP6kspqtougqjo60PRhIFo+oAxrjkof14WMCImvr7acK6rPpXLw=="
|
||||
},
|
||||
"node_modules/protocol-buffers-schema": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.6.0.tgz",
|
||||
"integrity": "sha512-TdDRD+/QNdrCGCE7v8340QyuXd4kIWIgapsE2+n/SaGiSSbomYl4TjHlvIoCWRpE7wFt02EpB35VVA2ImcBVqw=="
|
||||
},
|
||||
"node_modules/protons": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/protons/-/protons-2.0.3.tgz",
|
||||
"integrity": "sha512-j6JikP/H7gNybNinZhAHMN07Vjr1i4lVupg598l4I9gSTjJqOvKnwjzYX2PzvBTSVf2eZ2nWv4vG+mtW8L6tpA==",
|
||||
"dependencies": {
|
||||
"protocol-buffers-schema": "^3.3.1",
|
||||
"signed-varint": "^2.0.1",
|
||||
"uint8arrays": "^3.0.0",
|
||||
"varint": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/signed-varint": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/signed-varint/-/signed-varint-2.0.1.tgz",
|
||||
"integrity": "sha1-UKmYnafJjCxh2tEZvJdHDvhSgSk=",
|
||||
"dependencies": {
|
||||
"varint": "~5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/time-to-seconds": {
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/time-to-seconds/-/time-to-seconds-1.1.5.tgz",
|
||||
@@ -85,6 +115,14 @@
|
||||
"vscode": "^1.22.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uint8arrays": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.0.0.tgz",
|
||||
"integrity": "sha512-HRCx0q6O9Bfbp+HHSfQQKD7wU70+lydKVt4EghkdOvlK/NlrF90z+eXV34mUd48rNvVJXwkrMSPpCATkct8fJA==",
|
||||
"dependencies": {
|
||||
"multiformats": "^9.4.2"
|
||||
}
|
||||
},
|
||||
"node_modules/underscore": {
|
||||
"version": "1.13.1",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz",
|
||||
@@ -99,9 +137,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/user-agents": {
|
||||
"version": "1.0.801",
|
||||
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.801.tgz",
|
||||
"integrity": "sha512-giB7GP2g71STtQaYbSDpd5T+XzbGr5ni+1NpEbeQnifnFiOIQeQonXOC2kDxGKvubzul6qQb/BwG9LlIQ1zxXA==",
|
||||
"version": "1.0.814",
|
||||
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.814.tgz",
|
||||
"integrity": "sha512-OU3lCkkaUCghnZiZuN2edSJ+//ituJihs3P1FCjCDwe1tMBS8eni68CQ0TBbPoVPDtoAqxM3Z7qbP7EWGlhBxA==",
|
||||
"dependencies": {
|
||||
"dot-json": "^1.2.2",
|
||||
"lodash.clonedeep": "^4.5.0"
|
||||
@@ -114,6 +152,11 @@
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/varint": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz",
|
||||
"integrity": "sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow=="
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -155,11 +198,48 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
|
||||
},
|
||||
"multiformats": {
|
||||
"version": "9.4.9",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.4.9.tgz",
|
||||
"integrity": "sha512-zA84TTJcRfRMpjvYqy63piBbSEdqlIGqNNSpP6kspqtougqjo60PRhIFo+oAxrjkof14WMCImvr7acK6rPpXLw=="
|
||||
},
|
||||
"protocol-buffers-schema": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.6.0.tgz",
|
||||
"integrity": "sha512-TdDRD+/QNdrCGCE7v8340QyuXd4kIWIgapsE2+n/SaGiSSbomYl4TjHlvIoCWRpE7wFt02EpB35VVA2ImcBVqw=="
|
||||
},
|
||||
"protons": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/protons/-/protons-2.0.3.tgz",
|
||||
"integrity": "sha512-j6JikP/H7gNybNinZhAHMN07Vjr1i4lVupg598l4I9gSTjJqOvKnwjzYX2PzvBTSVf2eZ2nWv4vG+mtW8L6tpA==",
|
||||
"requires": {
|
||||
"protocol-buffers-schema": "^3.3.1",
|
||||
"signed-varint": "^2.0.1",
|
||||
"uint8arrays": "^3.0.0",
|
||||
"varint": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"signed-varint": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/signed-varint/-/signed-varint-2.0.1.tgz",
|
||||
"integrity": "sha1-UKmYnafJjCxh2tEZvJdHDvhSgSk=",
|
||||
"requires": {
|
||||
"varint": "~5.0.0"
|
||||
}
|
||||
},
|
||||
"time-to-seconds": {
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/time-to-seconds/-/time-to-seconds-1.1.5.tgz",
|
||||
"integrity": "sha512-mpzJDHGF4VdhiahyusCUSy+BWJdN3q8Cluzfy0n7GMU9IIj+HJDX9bbbr7wVSUiqmRn1vqhhfECgdfj+SByu2A=="
|
||||
},
|
||||
"uint8arrays": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.0.0.tgz",
|
||||
"integrity": "sha512-HRCx0q6O9Bfbp+HHSfQQKD7wU70+lydKVt4EghkdOvlK/NlrF90z+eXV34mUd48rNvVJXwkrMSPpCATkct8fJA==",
|
||||
"requires": {
|
||||
"multiformats": "^9.4.2"
|
||||
}
|
||||
},
|
||||
"underscore": {
|
||||
"version": "1.13.1",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz",
|
||||
@@ -174,9 +254,9 @@
|
||||
}
|
||||
},
|
||||
"user-agents": {
|
||||
"version": "1.0.801",
|
||||
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.801.tgz",
|
||||
"integrity": "sha512-giB7GP2g71STtQaYbSDpd5T+XzbGr5ni+1NpEbeQnifnFiOIQeQonXOC2kDxGKvubzul6qQb/BwG9LlIQ1zxXA==",
|
||||
"version": "1.0.814",
|
||||
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.814.tgz",
|
||||
"integrity": "sha512-OU3lCkkaUCghnZiZuN2edSJ+//ituJihs3P1FCjCDwe1tMBS8eni68CQ0TBbPoVPDtoAqxM3Z7qbP7EWGlhBxA==",
|
||||
"requires": {
|
||||
"dot-json": "^1.2.2",
|
||||
"lodash.clonedeep": "^4.5.0"
|
||||
@@ -186,6 +266,11 @@
|
||||
"version": "8.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||
},
|
||||
"varint": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz",
|
||||
"integrity": "sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "youtubei.js",
|
||||
"version": "1.0.5",
|
||||
"version": "1.2.2",
|
||||
"description": "An object-oriented library that allows you to search, get detailed info about videos, subscribe, unsubscribe, like, dislike, comment, download videos and much more!",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -14,6 +14,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.4",
|
||||
"protons": "^2.0.3",
|
||||
"time-to-seconds": "^1.1.5",
|
||||
"user-agents": "^1.0.778",
|
||||
"uuid": "^8.3.2"
|
||||
@@ -27,13 +28,15 @@
|
||||
"youtube-dl",
|
||||
"innertube",
|
||||
"innertubeapi",
|
||||
"livechat",
|
||||
"api",
|
||||
"search",
|
||||
"like",
|
||||
"dislike",
|
||||
"comment",
|
||||
"downloader",
|
||||
"automation",
|
||||
"downloader",
|
||||
"comments-section",
|
||||
"youtube-downloader"
|
||||
],
|
||||
"bugs": {
|
||||
|
||||
Reference in New Issue
Block a user