Skip to content

Commit

Permalink
Merge pull request #45 from gatecrasher777/update2
Browse files Browse the repository at this point in the history
New traverse code extraction
  • Loading branch information
gatecrasher777 authored Aug 30, 2022
2 parents 129a80e + ad24772 commit 0109ece
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class Player extends Model {
// extract signature manipulations - caller is the section of the player body concerned
extractManipulations(caller) {
let fname = ut.pinch(caller, 'a=a.split("");', '.', 0, 0, '', false);
let ffunc = `var ${fname}={`;
return `${ffunc}${ut.pinch(this.data,ffunc,')}};',0,0,'',false)})}};`
let ffunc = `var ${fname}=`;
return `${ut.traverse(this.data, ffunc)}`;
}

// extracts signature decipher function
extractDecipher() {
let fname = ut.pinch(this.data, 'a.set("alr","yes");c&&(c=', '(decodeURIC', 0, 0, '', false);
let ffunc = `${fname}=function(a)`;
ffunc = `var ${ffunc}${ut.pinch(this.data, ffunc, '.join("")};', 0,0,'',false)}.join("")};`;
ffunc = `var ${ut.traverse(this.data, ffunc)}`;
ffunc = `${this.extractManipulations(ffunc)};${ffunc};return ${fname}(ytcogsig);`;
let decipherScript = new vm.VMScript(`( function(ytcogsig) {${ffunc}} )`).compile();
this.decipherFn = this.context.run(decipherScript);
Expand All @@ -46,7 +46,7 @@ class Player extends Model {
fname = ut.pinch(this.data, `${fname.split('[')[0]}=[`, ']', 0, 0, '', false);
}
let ffunc = `${fname}=function(a)`;
ffunc = `var ${ffunc}${ut.pinch(this.data, ffunc, '.join("")};',0,0,'',false)}.join("")};`;
ffunc = `var ${ut.traverse(this.data, ffunc)}`;
ffunc = `${ffunc};return ${fname}(ytcogncode);`;
let ncodeScript = new vm.VMScript(`( function(ytcogncode) {${ffunc}} )`).compile();
this.ncodeFn = this.context.run(ncodeScript);
Expand All @@ -59,7 +59,7 @@ class Player extends Model {
let fname = ut.pinch(prefix, '=', '();', 0, 0, '', false);
let fname2 = ut.pinch(this.data, start, '()', 0, 0, '', false);
let ffunc = `${fname}=function()`;
ffunc = `var ${ffunc}${ut.pinch(this.data, ffunc, '}}};', 0,0,'',false)}}}};`;
ffunc = `var ${ut.traverse(this.data, ffunc)}`;
ffunc = `${ffunc};
var host = "https://www.youtube.com";
var ts = Math.floor((new Date).getTime() / 1E3);
Expand Down
55 changes: 55 additions & 0 deletions lib/ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,61 @@ class utClass {
return extract;
}

// returns extracted javascript code block {} or array [] from body string.
// starting directly after start text
traverse(body, start) {
let spos = body.indexOf(start);
let pos = spos + start.length;
const objs = [
{ start: '"', end: '"' },
{ start: "'", end: "'" },
{ start: '`', end: '`' },
{ start: '/', end: '/', prefix: /(^|[[{:;,])\s+$/ },
];
let op = '';
let cl = '';
if (body[pos] === '[') {
op = '[';
cl = ']';
} else if (body[pos] === '{') {
op = '{';
cl = '}';
}
if (!op.length) return '';
let obj = null;
let esc = false;
let level = 0;
let done = false;
while (!done) {
if (!esc && obj !== null && body[pos] === obj.end) {
obj = null;
} else if (!esc && obj === null) {
for (const o of objs) {
if (
body[pos] === o.start
&&
(!o.prefix || body.substring(pos - 10, pos).match(o.prefix))
) {
obj = o;
break;
}
}
}
esc = body[pos] === '\\' && !esc;
if (obj === null) {
if (body[pos] === op) {
level++;
} else if (body[pos] === cl) {
level--;
}
if (level === 0) return body.substring(spos, pos + 1);
}
pos++;
if (pos >= body.length) done = true;
}
return '';
};

}

// Initiate the class
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ytcog",
"version": "2.4.0",
"version": "2.4.1",
"description": "YouTube innertube class library for node-js; session, player, searches, channels, playlists, videos and downloads.",
"main": "./lib/index.js",
"repository": {
Expand Down

0 comments on commit 0109ece

Please sign in to comment.