Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

youtubei.js

Package Overview
Dependencies
Maintainers
1
Versions
124
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.2.9-a to 1.2.9-b

20

lib/Constants.js

@@ -51,4 +51,4 @@ 'use strict';

const origin = info.ytmusic && 'https://music.youtube.com' ||
info.desktop && 'https://www.youtube.com' || 'https://m.youtube.com';
info.desktop && 'https://www.youtube.com' || 'https://m.youtube.com';
let req_opts = {

@@ -109,3 +109,3 @@ params: info.params || {},

BLACKLISTED_KEYS: [
'is_owner_viewing', 'is_unplugged_corpus',
'is_owner_viewing', 'is_unplugged_corpus',
'is_crawlable', 'allow_ratings', 'author'

@@ -117,3 +117,3 @@ ],

},
FUNCS_REGEX: /d\.push\(e\)|d\.reverse\(\)|d\[0\]\)\[0\]\)|f=d\[0];d\[0\]|d\.length;d\.splice\(e,1\)|function\(\){for\(var|function\(d,e,f\){var h=f|function\(d\){for\(var|reverse\(\)\.forEach|unshift\(d\.pop\(\)\)|function\(d,e\){for\(var f/,
FUNCS_REGEX: /d\.push\(e\)|d\.reverse\(\)|d\[0\]\)\[0\]\)|f=d\[0];d\[0\]|d\.length;d\.splice\(e,1\)|function\(\){for\(var|function\(d,e,f\){var|function\(d\){for\(var|reverse\(\)\.forEach|unshift\(d\.pop\(\)\)|function\(d,e\){for\(var f/,
FUNCS: {

@@ -130,14 +130,4 @@ PUSH: 'd.push(e)',

TRANSLATE_1: 'function(d,e){for(var f',
TRANSLATE_2: 'function(d,e,f){var h=f'
},
// Just a helper function, felt like Utils.js wasn't the right place for it:
formatNTransformData: (data) => {
return data
.replace(/function\(d,e\)/g, '"function(d,e)').replace(/function\(d\)/g, '"function(d)')
.replace(/function\(\)/g, '"function()').replace(/function\(d,e,f\)/g, '"function(d,e,f)')
.replace(/\[function\(d,e,f\)/g, '["function(d,e,f)').replace(/,b,/g, ',"b",')
.replace(/,b/g, ',"b"').replace(/b,/g, '"b",').replace(/b]/g, '"b"]')
.replace(/\[b/g, '["b"').replace(/}]/g, '"]').replace(/},/g, '}",')
.replace(/""/g, '').replace(/length]\)}"/g, 'length])}');
TRANSLATE_2: 'function(d,e,f){var'
}
};

@@ -9,4 +9,4 @@ 'use strict';

this.raw_code = raw_code;
this.null_placeholder_regex = /c\[(.*?)\]=c/g;
this.transformation_calls_regex = /c\[(.*?)\]\((.+?)\)/g;
this.placeholders_regex = /c\[(.*?)\]=c/g;
this.calls_regex = /c\[(.*?)\]\((.+?)\)/g;
}

@@ -45,11 +45,11 @@

// Fills the null placeholders with a copy of the transformations array
const null_placeholder_positions = [...this.raw_code.matchAll(this.null_placeholder_regex)].map((item) => parseInt(item[1]));
null_placeholder_positions.forEach((pos) => transformations[pos] = transformations);
// Fills all placeholders with the transformations array
const placeholder_indexes = [...this.raw_code.matchAll(this.placeholders_regex)].map((item) => parseInt(item[1]));
placeholder_indexes.forEach((i) => transformations[i] = transformations);
// Parses and emulates calls to the functions of the transformations array
const transformation_calls = [...Utils.getStringBetweenStrings(this.raw_code.replace(/\n/g, ''), 'try{', '}catch')
.matchAll(this.transformation_calls_regex)].map((params) => ({ index: params[1], params: params[2] }));
const function_calls = [...Utils.getStringBetweenStrings(this.raw_code.replace(/\n/g, ''), 'try{', '}catch')
.matchAll(this.calls_regex)].map((params) => ({ index: params[1], params: params[2] }));
transformation_calls.forEach((data) => {
function_calls.forEach((data) => {
const param_index = data.params.split(',').map((param) => param.match(/c\[(.*?)\]/)[1]);

@@ -60,3 +60,3 @@ const base64_dia = (param_index[2] && transformations[param_index[2]]());

} catch (err) {
console.error(`Could not transform n-token (${n}), download may be throttled:`, err)
console.error(`Could not transform n-token (${n}), download may be throttled:`, err);
return n;

@@ -77,3 +77,3 @@ }

const data = `[${Utils.getStringBetweenStrings(this.raw_code.replace(/\n/g, ''), 'c=[', '];c')}]`;
return JSON.parse(Constants.formatNTransformData(data));
return JSON.parse(Utils.refineNTokenData(data));
}

@@ -80,0 +80,0 @@

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

* WIP
**/
**/
const getLyrics = async (id) => {

@@ -137,3 +137,3 @@ // const data_continuation = await Actions.getContinuation(this.session, { video_id: id, ytmusic: true });

if (playability_status.status == 'ERROR')
if (playability_status.status == 'ERROR')
throw new Error(`Could not retrieve details for this video: ${playability_status.status} - ${playability_status.reason}`);

@@ -140,0 +140,0 @@

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

Fs.writeFileSync(`${this.tmp_cache_dir}/${this.player_name}.js`, response.data);
} catch (err) {}
} catch (err) { }

@@ -31,0 +31,0 @@ this.sig_decipher_sc = this.#getSigDecipherCode(response.data);

@@ -15,5 +15,5 @@ 'use strict';

/**
* Deciphers signature.
*/
/**
* Deciphers signature.
*/
decipher() {

@@ -20,0 +20,0 @@ const args = QueryString.parse(this.url);

@@ -159,5 +159,5 @@ 'use strict';

const periods = { 'any': null, 'hour': 1, 'day': 2, 'week': 3, 'month': 4, 'year': 5 };
const durations = { 'any': null, 'short' : 1, 'long': 2 };
const orders = { 'relevance': null, 'rating': 1, 'age': 2, 'views' : 3 };
const durations = { 'any': null, 'short': 1, 'long': 2 };
const orders = { 'relevance': null, 'rating': 1, 'age': 2, 'views': 3 };
const search_filter_buff = youtube_proto.SearchFilter.encode({

@@ -171,6 +171,21 @@ number: orders[order],

});
return encodeURIComponent(Buffer.from(search_filter_buff).toString('base64'));
}
module.exports = { getRandomUserAgent, generateSidAuth, getStringBetweenStrings, camelToSnake, timeToSeconds, encodeMessageParams, encodeCommentParams, encodeNotificationPref, encodeFilter };
/**
* Turns the ntoken transform data into a valid json array
*
* @param {string} data
*/
function refineNTokenData(data) {
return data
.replace(/function\(d,e\)/g, '"function(d,e)').replace(/function\(d\)/g, '"function(d)')
.replace(/function\(\)/g, '"function()').replace(/function\(d,e,f\)/g, '"function(d,e,f)')
.replace(/\[function\(d,e,f\)/g, '["function(d,e,f)').replace(/,b,/g, ',"b",')
.replace(/,b/g, ',"b"').replace(/b,/g, '"b",').replace(/b]/g, '"b"]')
.replace(/\[b/g, '["b"').replace(/}]/g, '"]').replace(/},/g, '}",')
.replace(/""/g, '').replace(/length]\)}"/g, 'length])}');
}
module.exports = { getRandomUserAgent, generateSidAuth, getStringBetweenStrings, camelToSnake, timeToSeconds, encodeMessageParams, encodeCommentParams, encodeNotificationPref, encodeFilter, refineNTokenData };
{
"name": "youtubei.js",
"version": "1.2.9-a",
"version": "1.2.9-b",
"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!",

@@ -5,0 +5,0 @@ "main": "index.js",

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

const youtube = await new Innertube().catch((error) => error);
assert(youtube instanceof Error ? false : true, `should retrieve Innertube configuration data`, youtube);
assert(!(youtube instanceof Error), `should retrieve Innertube configuration data`, youtube);

@@ -62,2 +62,2 @@ if (!(youtube instanceof Error)) {

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