New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

youtubei.js

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

youtubei.js - npm Package Compare versions

Comparing version 1.4.1-dev.1 to 1.4.1-dev.2

lib/deciphers/Signature.js

30

lib/core/Actions.js

@@ -67,3 +67,3 @@ 'use strict';

const response = await session.YTRequester.post(`/${engagement_type}`, JSON.stringify(data)).catch((error) => error);
const response = await session.request.post(`/${engagement_type}`, JSON.stringify(data)).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response.response?.status || 0, message: response.message };

@@ -133,4 +133,3 @@

const requester = args.ytmusic && session.YTMRequester || session.YTRequester;
const response = await requester.post('/browse', JSON.stringify(data)).catch((error) => error);
const response = await session.request.post('/browse', JSON.stringify(data)).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response.response?.status || 0, message: response.message };

@@ -171,3 +170,3 @@

const response = await session.YTRequester.post(`/${action}`, JSON.stringify(data)).catch((error) => error);
const response = await session.request.post(`/${action}`, JSON.stringify(data)).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response.response?.status || 0, message: response.message };

@@ -208,3 +207,3 @@

const response = await session.YTMRequester.post(`/music/${action}`, JSON.stringify(data)).catch((error) => error);
const response = await session.request.post(`/music/${action}`, JSON.stringify(data)).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response.response?.status || 0, message: response.message };

@@ -252,4 +251,3 @@

const requester = client == 'YOUTUBE' && session.YTRequester || session.YTMRequester;
const response = await requester.post('/search', JSON.stringify(data)).catch((error) => error);
const response = await session.request.post('/search', JSON.stringify(data)).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response.response?.status || 0, message: response.message };

@@ -294,3 +292,3 @@

const response = await session.YTRequester.post(`/notification/${action}`, JSON.stringify(data)).catch((err) => err);
const response = await session.request.post(`/notification/${action}`, JSON.stringify(data)).catch((err) => err);
if (response instanceof Error) return { success: false, status_code: response.response?.status || 0, message: response.message };

@@ -324,3 +322,3 @@ if (action === 'modify_channel_preference') return { success: true, status_code: response.status };

data.params = Proto.encodeMessageParams(args.channel_id, args.video_id);
data.clientMessageId = `ytjs-${Uuid.v4()}`;
data.clientMessageId = Uuid.v4();
data.richMessage = {

@@ -346,3 +344,3 @@ textSegments: [{ text: args.text }]

const response = await session.YTRequester.post(`/${action}`, JSON.stringify(data)).catch((err) => err);
const response = await session.request.post(`/${action}`, JSON.stringify(data)).catch((err) => err);
if (response instanceof Error) return { success: false, message: response.message };

@@ -385,10 +383,4 @@

const requester = args.ytmusic && session.YTMRequester || session.YTRequester;
const response = await requester.post('/next', JSON.stringify(data)).catch((error) => error);
if (response instanceof Error) return {
success: false,
status_code: response.response?.status || 0,
message: response.message
};
const response = await session.request.post('/next', JSON.stringify(data)).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response?.status || 0, message: response.message };

@@ -410,3 +402,3 @@ return {

async function getVideoInfo(session, args = {}) {
const response = await session.YTRequester.post(`/player`, JSON.stringify(Constants.VIDEO_INFO_REQBODY(args.id, session.sts, session.context))).catch((err) => err);
const response = await session.request.post(`/player`, JSON.stringify(Constants.VIDEO_INFO_REQBODY(args.id, session.sts, session.context))).catch((err) => err);
if (response instanceof Error) throw new Utils.InnertubeError(`Could not get video info: ${response.message}`);

@@ -413,0 +405,0 @@ return response.data;

@@ -15,6 +15,7 @@ 'use strict';

const Utils = require('./utils/Utils');
const Request = require('./utils/Request');
const Constants = require('./utils/Constants');
const NToken = require('./deciphers/NToken');
const SigDecipher = require('./deciphers/Sig');
const Signature = require('./deciphers/Signature');

@@ -75,18 +76,5 @@ class Innertube {

}
// Axios instances
this.YTRequester = Axios.create({
baseURL: Constants.URLS.YT_BASE_API + this.version,
timeout: 15000,
headers: Constants.INNERTUBE_HEADERS({ session: this, ytmusic: false }),
params: { key: this.key }
});
this.YTMRequester = Axios.create({
baseURL: Constants.URLS.YT_MUSIC_BASE_API + this.version,
timeout: 15000,
headers: Constants.INNERTUBE_HEADERS({ session: this, ytmusic: true }),
params: { key: this.key }
});
this.request = new Request(this);
this.#initMethods();

@@ -327,10 +315,2 @@ } else {

this.logged_in = true;
// API key is not needed if logged in via OAuth
delete this.YTRequester.defaults.params.key;
delete this.YTMRequester.defaults.params.key;
// Update default headers
this.YTRequester.defaults.headers = Constants.INNERTUBE_HEADERS({ session: this, ytmusic: false });
this.YTMRequester.defaults.headers = Constants.INNERTUBE_HEADERS({ session: this, ytmusic: true });
}

@@ -704,3 +684,3 @@

if (format.signatureCipher || format.cipher) {
format.url = new SigDecipher(format.url, this.#player).decipher();
format.url = new Signature(format.url, this.#player).decipher();
}

@@ -707,0 +687,0 @@

'use strict';
const Fs = require('fs');
const Protons = require('protons');
const messages = Protons(Fs.readFileSync(`${__dirname}/youtube.proto`));
const messages = require('./messages');

@@ -39,3 +38,3 @@ class Proto {

});
return encodeURIComponent(Buffer.from(buf).toString('base64'));

@@ -42,0 +41,0 @@ }

@@ -53,29 +53,5 @@ 'use strict';

},
INNERTUBE_HEADERS: (info) => {
const origin = info.ytmusic && 'https://music.youtube.com' || 'https://www.youtube.com';
const headers = {
'accept': '*/*',
'user-agent': Utils.getRandomUserAgent('desktop').userAgent,
'content-type': 'application/json',
'accept-language': `en-${info.session.config.gl || 'US'}`,
'x-goog-authuser': 0,
'x-goog-visitor-id': info.session.context.client.visitorData || '',
'x-youtube-client-name': 1,
'x-youtube-client-version': info.session.context.client.clientVersion,
'x-youtube-chrome-connected': 'source=Chrome,mode=0,enable_account_consistency=true,supervised=false,consistency_enabled_by_default=false',
'x-origin': origin,
'origin': origin
};
const auth_creds = info.session.cookie
&& info.session.auth_apisid
|| `Bearer ${info.session.access_token}`;
if (info.session.logged_in) {
headers.cookie = info.session.config.cookie || '';
headers.authorization = auth_creds;
}
return headers;
INNERTUBE_HEADERS_BASE: {
'accept': '*/*',
'content-type': 'application/json',
},

@@ -82,0 +58,0 @@ VIDEO_INFO_REQBODY: (id, sts, context) => {

'use strict';
const Fs = require('fs');
const Crypto = require('crypto');

@@ -5,0 +4,0 @@ const UserAgent = require('user-agents');

{
"name": "youtubei.js",
"version": "1.4.1-dev.1",
"version": "1.4.1-dev.2",
"description": "A full-featured library that allows you to get detailed info about any video, subscribe, unsubscribe, like, dislike, comment, search, download videos/music and much more!",

@@ -25,3 +25,3 @@ "main": "index.js",

"flat": "^5.0.2",
"protons": "^2.0.3",
"protocol-buffers-encodings": "^1.1.1",
"user-agents": "^1.0.778",

@@ -28,0 +28,0 @@ "uuid": "^8.3.2"

@@ -108,3 +108,3 @@ <h1 align=center>YouTube.js</h1>

First of all we're gonna start by initializing the Innertube instance.
And to make things faster, you should do this only once and re-use the Innertube object when needed.
And to make things faster, you should do this only once and reuse the Innertube object when needed.

@@ -1081,3 +1081,3 @@ ```js

async function start() {
const youtube = await new Innertube(COOKIE_HERE);
const youtube = await new Innertube({ cookie: '...' });
//...

@@ -1084,0 +1084,0 @@ }

@@ -6,3 +6,3 @@ 'use strict';

const NToken = require('../lib/deciphers/NToken');
const SigDecipher = require('../lib/deciphers/Sig');
const SigDecipher = require('../lib/deciphers/Signature');
const Constants = require('./constants');

@@ -28,6 +28,6 @@

assert(!(ytsearch_suggestions instanceof Error), `should retrieve YouTube search suggestions`, ytsearch_suggestions);
const ytmsearch_suggestions = await youtube.getSearchSuggestions('test', { client: 'YTMUSIC' }).catch((error) => error);
assert(!(ytmsearch_suggestions instanceof Error), `should retrieve YouTube Music search suggestions`, ytmsearch_suggestions);
const ytmsearch_suggestions = await youtube.getSearchSuggestions('test', { client: 'YTMUSIC' });
assert(!(ytmsearch_suggestions instanceof Error), `should retrieve YouTube Music search suggestions`);
const details = await youtube.getDetails(Constants.test_video_id).catch((error) => error);

@@ -75,3 +75,3 @@ assert(!(details instanceof Error), `should retrieve details for ${Constants.test_video_id}`, details);

const pass_fail = outcome ? 'pass' : 'fail';
console.info(pass_fail, ':', description);

@@ -84,2 +84,2 @@ !outcome && (failed_tests_count += 1);

performTests();
performTests();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc