Skip to content

Commit

Permalink
Merge pull request #47 from gatecrasher777/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
gatecrasher777 authored Sep 1, 2022
2 parents 0109ece + 78bbecf commit 96b92fa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
58 changes: 40 additions & 18 deletions lib/ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,37 @@ class utClass {
return extract;
}

// returns length of object to be ignored with start/end characters.
// objects muct be less than 1024 characters.
// If object is regex, will test if regex is valid.
// if invalid regex or unterminated object, will report a 0 object length.
ignore(body, spos, start, end) {
let p = spos;
let s = start;
let esc = false;
let c = 0;
while (true) {
s += body[p];
if (!esc && body[p] === end) {
if (end === '/') {
try {
let r = new RegExp(s);
return s.length;
}
catch(e) {
}
} else {
return s.length;
}
}
esc = body[p] === '\\' && !esc;
p++;
c++;
if (p >= body.length) return 0;
if (c > 1024) return 0;
}
}

// returns extracted javascript code block {} or array [] from body string.
// starting directly after start text
traverse(body, start) {
Expand All @@ -209,7 +240,7 @@ class utClass {
{ start: '"', end: '"' },
{ start: "'", end: "'" },
{ start: '`', end: '`' },
{ start: '/', end: '/', prefix: /(^|[[{:;,])\s+$/ },
{ start: '/', end: '/' }
];
let op = '';
let cl = '';
Expand All @@ -221,34 +252,25 @@ class utClass {
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) {
if (!esc) {
for (const o of objs) {
if (
body[pos] === o.start
&&
(!o.prefix || body.substring(pos - 10, pos).match(o.prefix))
) {
obj = o;
if (body[pos] === o.start) {
pos += this.ignore(body,pos+1,o.start,o.end);
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);
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;
}
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.1",
"version": "2.4.2",
"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 96b92fa

Please sign in to comment.