Skip to content

Commit

Permalink
Merge pull request #43 from gatecrasher777/update
Browse files Browse the repository at this point in the history
Update - remove block parse function, add itag, reduce timeout durations.
  • Loading branch information
gatecrasher777 authored Aug 25, 2022
2 parents 0aa3b87 + f7a7cf1 commit 129a80e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 52 deletions.
6 changes: 4 additions & 2 deletions lib/dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Download {
this.attempt = 0;
this.logging = data.logging;
this.cancelled = false;
this.timeout = 60000;
this.timeout = 10000;
this.maxSection = 0;
this.curSection = 0;
this.data = data;
Expand Down Expand Up @@ -237,6 +237,7 @@ class Download {
delete this.opts.headers.Range;
}
this.vrs = miniget(this.data.stream.video_url, this.opts);
this.tmo = setTimeout(this.timedOut.bind(this), this.timeout);
this.vrs.pipe(this.vws, { end: this.curSection === this.maxSection });
this.vrs.on('data', this.dataChunk.bind(this));
this.vrs.on('error', this.dataError.bind(this));
Expand Down Expand Up @@ -272,6 +273,7 @@ class Download {
delete this.opts.headers.Range;
}
this.ars = miniget(this.data.stream.audio_url, this.opts);
this.tmo = setTimeout(this.timedOut.bind(this), this.timeout);
this.ars.pipe(this.aws, { end: this.curSection === this.maxSection });
this.ars.on('data', this.dataChunk.bind(this));
this.ars.on('error', this.dataError.bind(this));
Expand Down Expand Up @@ -341,7 +343,7 @@ class Download {
process.on('message', msg => {
switch (msg.msg) {
case 'retry':
dl.retry(30000);
dl.retry(10000);
break;
case 'download':
dl = new Download(msg.data);
Expand Down
8 changes: 4 additions & 4 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class Player extends Model {
extractManipulations(caller) {
let fname = ut.pinch(caller, 'a=a.split("");', '.', 0, 0, '', false);
let ffunc = `var ${fname}={`;
return ut.block(this.data, ffunc, 1, '{', '}', '{}', false);
return `${ffunc}${ut.pinch(this.data,ffunc,')}};',0,0,'',false)})}};`
}

// 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 ${ut.block(this.data, ffunc, 0, '{', '}', '{}', false)}`;
ffunc = `var ${ffunc}${ut.pinch(this.data, ffunc, '.join("")};', 0,0,'',false)}.join("")};`;
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 ${ut.block(this.data, ffunc, 0, '{', '}', '{}', false)}`;
ffunc = `var ${ffunc}${ut.pinch(this.data, ffunc, '.join("")};',0,0,'',false)}.join("")};`;
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 ${ut.block(this.data, ffunc, 0, '{', '}', '{}', false)}`;
ffunc = `var ${ffunc}${ut.pinch(this.data, ffunc, '}}};', 0,0,'',false)}}}};`;
ffunc = `${ffunc};
var host = "https://www.youtube.com";
var ts = Math.floor((new Date).getTime() / 1E3);
Expand Down
43 changes: 0 additions & 43 deletions lib/ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,49 +200,6 @@ class utClass {
return extract;
}

// iterates through body from start text less snip characters
// on an open character it increments level, on a close character it decrements level
// it ends when level return to zero.
// provide what an empty results looks like
// optionally truncate the body at the end of the end text.
block(body, start, snip, open, close, empty, truncate) {
let extract = empty;
let spos = body.indexOf(start);
let slen = start.length;
if (spos >= 0) {
let pos = spos + slen - snip;
let done = false;
let level = 0;
let alevel = 0;
let inq = false;
let inr = false;
extract = start.substr(0, slen - snip);
while (!done) {
switch (body[pos]) {
case '"': inq = !inq;
break;
case '/': if (!['1','2','3','4','5','6','7','8','9'].includes(body[pos+1])) inr = !inr;
break;
case '[': if (!inq && !inr) alevel++;
break;
case ']': if (!inq && !inr) alevel--;
break;
case open:
if (!inq && !inr && !alevel) level++;
break;
case close:
if (!inq && !inr && !alevel) level--;
if (!level) done = true;
break;
}
extract += body[pos];
pos++;
if (pos >= body.length) done = true;
}
if (truncate) body = body.substring(0, pos);
} else if (truncate) { body = ''; }
return extract;
}
}

// Initiate the class
Expand Down
4 changes: 2 additions & 2 deletions lib/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ class Video extends Model {
this.downloaded = ut.now();
} else if (!this.cancelled) {
// try video onloy
if ((aformat >= 0) && !vonly && !aonly && ((vformat >= 0) || (aformat >= 0))) {
if (aformat < 0 && !vonly && !aonly && vformat < 0) {
success = await this.downloadAttempt(true, false, vformat, aformat);
if (success) this.downloaded = ut.now();
}
Expand Down Expand Up @@ -1269,4 +1269,4 @@ class Video extends Model {
}
}

module.exports = Video;
module.exports = Video;
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.3.4",
"version": "2.4.0",
"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 129a80e

Please sign in to comment.