Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Missing catch or finally after try #1113

Closed
ab2103 opened this issue Aug 19, 2022 · 20 comments · Fixed by #1126
Closed

SyntaxError: Missing catch or finally after try #1113

ab2103 opened this issue Aug 19, 2022 · 20 comments · Fixed by #1126
Labels

Comments

@ab2103
Copy link

ab2103 commented Aug 19, 2022

Code :-

const ytdl = require('ytdl-core');

ytdl.getInfo('http://www.youtube.com/watch?v=aqz-KE-bpKQ')
.then( d => console.log(d))
.catch(e => console.error(e));

Expected Behaviour
log the video info

Ouptut on Console

evalmachine.<anonymous>:24
c[72],c[6]),(0,c[85])(c[11]),(0,c[41])(c[39],c[28],(0,c[66])()),(0,c[78])(c[Math.pow(6,2)+122+-119],c[new Date("Wednesday December 31 1969 19:00:14 CDT")/1E3])}catch(d){(0<c[0]||(((0,c[80])(c[60],c[88]),c[80])(c[21],c[88]),0))&&(0,c[17])((0,c[70])(c[6]),c[78],c[88],c[12])}try{2<c[91]&&(1<c[53]?(0,c[17])((0,c[80])(c[82],c[6]),c[78],c[39],c[5]):((0,c[45])(c[49],c[88]),c[78])(c[88],c[86])),(0,c[17])((0,c[85])(c[31]),c[41],c[88],c[75],(0,c[35])())}catch(d){}};Wka(ncode);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ^

SyntaxError: Missing catch or finally after try
    at new Script (node:vm:100:7)
    at exports.decipherFormats (/storage/emulated/0/c/ytdl/node_modules/ytdl-core/lib/sig.js:116:51)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async exports.getInfo (/storage/emulated/0/c/ytdl/node_modules/ytdl-core/lib/info.js:401:17)

Node.js v18.7.0
@bwees
Copy link

bwees commented Aug 19, 2022

This is also happening to me. Not sure what the issue is?

@davidgalarza
Copy link

I'm facing the same issue

@bwees
Copy link

bwees commented Aug 19, 2022

Rolling back to 4.10.0 fixes problem for me

@davidgalarza
Copy link

davidgalarza commented Aug 19, 2022

@bwees I can confirm that downgrading to version 4.10.0 fixes the issue, but in my case the download speed decrease a lot.
(6 minutes to download a 2 minutes video with a good internet connection).

@Zowlyfon
Copy link

I've debugged the issue, it is thrown by this line

const nTransformScript = functions.length > 1 ? new vm.Script(functions[1]) : null;

The issue stems from somewhere in this function

exports.extractFunctions = body => {
const functions = [];
const extractManipulations = caller => {
const functionName = utils.between(caller, `a=a.split("");`, `.`);
if (!functionName) return '';
const functionStart = `var ${functionName}={`;
const ndx = body.indexOf(functionStart);
if (ndx < 0) return '';
const subBody = body.slice(ndx + functionStart.length - 1);
return `var ${functionName}=${utils.cutAfterJSON(subBody)}`;
};
const extractDecipher = () => {
const functionName = utils.between(body, `a.set("alr","yes");c&&(c=`, `(decodeURIC`);
if (functionName && functionName.length) {
const functionStart = `${functionName}=function(a)`;
const ndx = body.indexOf(functionStart);
if (ndx >= 0) {
const subBody = body.slice(ndx + functionStart.length);
let functionBody = `var ${functionStart}${utils.cutAfterJSON(subBody)}`;
functionBody = `${extractManipulations(functionBody)};${functionBody};${functionName}(sig);`;
functions.push(functionBody);
}
}
};
const extractNCode = () => {
let functionName = utils.between(body, `&&(b=a.get("n"))&&(b=`, `(b)`);
if (functionName.includes('[')) functionName = utils.between(body, `${functionName.split('[')[0]}=[`, `]`);
if (functionName && functionName.length) {
const functionStart = `${functionName}=function(a)`;
const ndx = body.indexOf(functionStart);
if (ndx >= 0) {
const subBody = body.slice(ndx + functionStart.length);
const functionBody = `var ${functionStart}${utils.cutAfterJSON(subBody)};${functionName}(ncode);`;
functions.push(functionBody);
}
}
};
extractDecipher();
extractNCode();
return functions;
};

Which appears to be transforming some compiled javascript code from youtube's html5 player, the transformed code seems to have illegal syntax.

I can confirm 4.10.0 is working for me

@larahfelipe
Copy link

Same problem here guys. Worked after rolling back to 4.10.10 here as well, but the download speed seems to have decreased a lot, not sure why. Anyway, guess we'll have to wait for further updates.

@770grappenmaker
Copy link

When replacing the line in onError calling console.error with console.trace, I was able to determine the code yielded by youtube that was invalid. This is what it looks like:

Trace: evalmachine.<anonymous>:24
c[72],c[6]),(0,c[85])(c[11]),(0,c[41])(c[39],c[28],(0,c[66])()),(0,c[78])(c[Math.pow(6,2)+122+-119],c[new Date("Wednesday December 31 1969 19:00:14 CDT")/1E3])}catch(d){(0<c[0]||(((0,c[80])(c[60],c[88]),c[80])(c[21],c[88]),0))&&(0,c[17])((0,c[70])(c[6]),c[78],c[88],c[12])}try{2<c[91]&&(1<c[53]?(0,c[17])((0,c[80])(c[82],c[6]),c[78],c[39],c[5]):((0,c[45])(c[49],c[88]),c[78])(c[88],c[86])),(0,c[17])((0,c[85])(c[31]),c[41],c[88],c[75],(0,c[35])())}catch(d){}};Wka(ncode);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ^

SyntaxError: Missing catch or finally after try
    at new Script (node:vm:100:7)
    at Object.exports.decipherFormats (\AppData\Roaming\npm\node_modules\ytdl\node_modules\ytdl-core\lib\sig.js:116:51)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 0)
    at async exports.getInfo (\AppData\Roaming\npm\node_modules\ytdl\node_modules\ytdl-core\lib\info.js:401:17)
    at onError (C:\Users\Koen\AppData\Roaming\npm\node_modules\ytdl\bin\ytdl.js:92:11)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

@ArjhanToteck
Copy link

Same issue for me

@dskaiser82
Copy link

PR for the Fix but missing "Maintainer approval"
Also @greepSheep did a Fork with the Fix...you can see his fork in the PR below

PR: #1111

@blrbrb
Copy link

blrbrb commented Aug 20, 2022

I've been having the exact same issue for some time now since around Friday. I thought it might have been an issue with the library so deleted the node-modules folder, and rebuilt. Still persisted. Re-installed my entire project on windows, same issue.

Edit: temp. fix works 👍

@gatecrasher777
Copy link
Contributor

Currently, the code traverses the base.js n transform function to extract it in full. But it gets tripped up with the inclusion of regular expressions, strings and possibly try-catch loops that include function closing braces, causing the process to short circuit.

The fix identifies the start of the function and the end of the function and simply extracts everything in between.

@CE1CECL
Copy link

CE1CECL commented Aug 21, 2022

Rolling back to 4.10.0 fixes problem for me

This fixed the issue until i got AudioPlayerError: Status code: 403, API key issue?

@BallisticOK
Copy link

rolling back don't fix for me i just get the same error as befor

@noviardi1986
Copy link

Any solution for this error? Rolling back to 4.10.0 take forever to download..

@bwees
Copy link

bwees commented Aug 21, 2022

@noviardi1986 it seems like switching to the fork of the project https://github.com/GreepTheSheep/node-ytdl-core is the best option as of now until the changes in that fork get pulled in

@Ben569483
Copy link

I'm also getting this issue, even on 4.10.0

@unclesam1991
Copy link

same issue for me. please fix it :(

nestarz pushed a commit to nestarz/remote-video-source that referenced this issue Aug 22, 2022
@noviardi1986
Copy link

g to the fork of the project https://github.com/GreepTheSheep/node-ytdl-core is the best option as of now unti

Thank Bro..

@noviardi1986
Copy link

Just reinstall ytdl-core the proble already been solve..

@github-actions
Copy link

🎉 This issue has been resolved in version 4.11.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet