Compare commits

..

5 Commits

Author SHA1 Message Date
LuanRT
aeff0c3fdc build (package): increment version 2021-11-19 13:50:50 -03:00
LuanRT
00d67ed417 chore (OAuth): better & simpler regular expression 2021-11-19 13:29:02 -03:00
LuanRT
78f93c7118 fix: add “g” flag so it matches all possible strings 2021-11-19 13:27:07 -03:00
LuanRT
6db3f0ad91 fix: download not possible due to visitorData being undefined 2021-11-14 12:22:56 -03:00
UnbreakCode
cf48385f72 fixed x-goog-visitor-id for downloader 2021-11-14 15:46:21 +01:00
4 changed files with 14 additions and 13 deletions

View File

@@ -54,7 +54,7 @@ module.exports = {
'content-type': 'application/json',
'accept-language': 'en-US,en;q=0.9',
'x-goog-authuser': 0,
'x-goog-visitor-id': info.session.context.client.visitorData,
'x-goog-visitor-id': info.session.context.client.visitorData || '',
'x-youtube-client-name': info.desktop ? 1 : 2,
'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',
@@ -113,7 +113,8 @@ module.exports = {
formatNTransformData: (data) => {
return data
.replace(/function\(d,e\)/g, '"function(d,e)').replace(/function\(d\)/g, '"function(d)')
.replace(/function\(\)/, '"function()').replace(/function\(d,e,f\)/g, '"function(d,e,f)')
.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])}');

View File

@@ -28,7 +28,7 @@ class OAuth extends EventEmitter {
this.auth_script_regex = /<script id=\"base-js\" src=\"(.*?)\" nonce=".*?"><\/script>/;
// Used to find the credentials inside the script.
this.identity_regex = /var .+?=\"(?<id>.+?)\",.?=\"(?<secret>.+?)\"/;
this.identity_regex = /var .+?=\"(?<id>.+?)\",.+?=\"(?<secret>.+?)\"/;
if (creds.access_token != undefined && creds.refresh_token != undefined) return;
this.requestAuthCode();
@@ -77,7 +77,7 @@ class OAuth extends EventEmitter {
const response = await Axios.get(script_url, Constants.DEFAULT_HEADERS).catch((error) => error);
if (response instanceof Error) throw new Error(`Could not extract client identify: ${response.message}`);
const identity_function = Utils.getStringBetweenStrings(response.data, 'YTLR_STORAGE_NAMESPACE",', 'reloadAppFlushLogsMaxTimeoutMs:');
const identity_function = Utils.getStringBetweenStrings(response.data, 'setQuery("");', '{useGaiaSandbox:');
const client_identity = identity_function.replace(/\n/g, '').match(this.identity_regex);
return client_identity.groups;
}

16
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "youtubei.js",
"version": "1.2.5",
"version": "1.2.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "youtubei.js",
"version": "1.2.5",
"version": "1.2.6",
"license": "MIT",
"dependencies": {
"axios": "^0.21.4",
@@ -137,9 +137,9 @@
}
},
"node_modules/user-agents": {
"version": "1.0.833",
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.833.tgz",
"integrity": "sha512-Vx6fikPUwMSR2emhgpVdmZz/OkiHS7f+n1hfW11US1dnYg7irTmBIP+or4R7GrG11ZU6J2hX3hx4iSriPPh67Q==",
"version": "1.0.840",
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.840.tgz",
"integrity": "sha512-pdXizW5mvcHRHsJH50STUA+zywDvUKbxouQ2523FEmfYJCkLMVGavBSOL7u/VVmneVXM2EX20Ikru9lCnbNDeQ==",
"dependencies": {
"dot-json": "^1.2.2",
"lodash.clonedeep": "^4.5.0"
@@ -254,9 +254,9 @@
}
},
"user-agents": {
"version": "1.0.833",
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.833.tgz",
"integrity": "sha512-Vx6fikPUwMSR2emhgpVdmZz/OkiHS7f+n1hfW11US1dnYg7irTmBIP+or4R7GrG11ZU6J2hX3hx4iSriPPh67Q==",
"version": "1.0.840",
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.840.tgz",
"integrity": "sha512-pdXizW5mvcHRHsJH50STUA+zywDvUKbxouQ2523FEmfYJCkLMVGavBSOL7u/VVmneVXM2EX20Ikru9lCnbNDeQ==",
"requires": {
"dot-json": "^1.2.2",
"lodash.clonedeep": "^4.5.0"

View File

@@ -1,6 +1,6 @@
{
"name": "youtubei.js",
"version": "1.2.5",
"version": "1.2.6",
"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": {