refactor: generate sessions manually

Session generation has been moved to `core/SessionBuilder.js`, which retrieves & generates all the required data to create a valid session. This should also decrease initialization time by over 600 milliseconds!
This commit is contained in:
LuanRT
2022-05-05 04:33:24 -03:00
parent 4943685e57
commit b0a861dec8
5 changed files with 160 additions and 56 deletions

View File

@@ -77,4 +77,4 @@ class Request {
}
}
module.exports = Request;
module.exports = Request;

View File

@@ -86,11 +86,11 @@ function generateSidAuth(sid) {
return ['SAPISIDHASH', [timestamp, gen_hash].join('_')].join(' ');
}
function generateContentPlaybackNonce() {
function generateRandomString(length) {
const result = [];
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
for (let i = 0; i < 16; i++) {
for (let i = 0; i < length; i++) {
result.push(alphabet.charAt(Math.floor(Math.random() * alphabet.length)));
}
@@ -139,6 +139,6 @@ function refineNTokenData(data) {
}
const errors = { UnavailableContentError, ParsingError, DownloadError, InnertubeError, MissingParamError, NoStreamingDataError };
const functions = { findNode, getRandomUserAgent, generateSidAuth, generateContentPlaybackNonce, getStringBetweenStrings, camelToSnake, timeToSeconds, refineNTokenData };
const functions = { findNode, getRandomUserAgent, generateSidAuth, generateRandomString, getStringBetweenStrings, camelToSnake, timeToSeconds, refineNTokenData };
module.exports = { ...functions, ...errors };