node-ytdl-core icon indicating copy to clipboard operation
node-ytdl-core copied to clipboard

Missing catch or finally after try - this error is back in 4.11.4 as well

Open arian0gen opened this issue 1 year ago • 16 comments

evalmachine.:24 c[74]),c[64])((0,c[25])(c[24],c[41]),c[35],c[33+Math.pow(8,3)%229],c[92]),c[70])(c[87],c[27])}try{8>=c[92]&&(0,c[15])((0,c[35])(c[36],c[20]),c[11],c[29])}catch(d){(0,c[60])(c[92],c[93])}try{1>c[45]?((0,c[60])(c[2],c[93]),c[60])(c[91],c[93]):((0,c[88])(c[93],c[86]),c[11])(c[57])}catch(d){(0,c[85])((0,c[80])(),c[56],c[0])}};qma(ncode);

                                 ^

SyntaxError: Missing catch or finally after try

arian0gen avatar Apr 26 '23 15:04 arian0gen

Same issue here. It happens but not every time.

Edit : You can use 4.10.0, it works but is kinda slow.

ZKillou avatar Apr 26 '23 18:04 ZKillou

I have the same issue : evalmachine.:24 c[74]),c[64])((0,c[25])(c[24],c[41]),c[35],c[33+Math.pow(8,3)%229],c[92]),c[70])(c[87],c[27])}try{8>=c[92]&&(0,c[15])((0,c[35])(c[36],c[20]),c[11],c[29])}catch(d){(0,c[60])(c[92],c[93])}try{1>c[45]?((0,c[60])(c[2],c[93]),c[60])(c[91],c[93]):((0,c[88])(c[93],c[86]),c[11])(c[57])}catch(d){(0,c[85])((0,c[80])(),c[56],c[0])}};qma(ncode);

Kisakay avatar Apr 26 '23 19:04 Kisakay

Exact same issue and error as the one mentioned above me.

danisty avatar Apr 26 '23 19:04 danisty

provisionally im using https://www.npmjs.com/package/@distube/ytdl-core work for me

Try this: "ytdl-core": "npm:@distube/ytdl-core",

Sansekai avatar Apr 26 '23 19:04 Sansekai

Happened a few hours ago a few times, then it worked again, now it's broken again

ShadowLp174 avatar Apr 26 '23 19:04 ShadowLp174

@Sansekai

provisionally im using https://www.npmjs.com/package/@distube/ytdl-core work for me

Try this: "ytdl-core": "npm:@distube/ytdl-core",

Don't forget to add the version number ^4.11.9

"ytdl-core": "npm:@distube/ytdl-core@^4.11.9"

ShadowLp174 avatar Apr 26 '23 19:04 ShadowLp174

this exact error was 2 weeks ago in 4.11.3 and then we freaked out, and then they fixed and now it is back again, it is probably because youtube keep changing their code so...

arian0gen avatar Apr 26 '23 20:04 arian0gen

This fork uses some custom HTTP client that doesn't play ball when you mock fetch in tests: https://www.npmjs.com/package/undici

It works in practice but it ruins all my test suites.

nukeop avatar Apr 26 '23 21:04 nukeop

After some research I've found that the problem has to do with the signature deciphering extraction of functions, specifically the extractNCode function, when calling cutAfterJS it fails to escape the following string /[/,-33,/,/]{/,function due to the literal / characters inside a RegEx character set, and so it counts opening and closing brackets incorrectly as it treats most part of the code as a regular expression, resulting in the script not getting to the end of the function and missing a catch block and a return statement.

TEMP FIX Add a check for RegEx character sets, replace https://github.com/fent/node-ytdl-core/blob/0d3f91b424e81aa79fc2ec021d921d4d21f3e6ef/lib/utils.js#L97-L102

with

  // Go through all characters from the start
  for (i = 0; i < mixedJson.length; i++) {
    // End of current escaped object
    if (!isEscaped && isEscapedObject !== null && mixedJson[i] === isEscapedObject.end) {
      // Ignore character inside RegEx character set with a range of 30 characters
      let charsetStart = mixedJson.substring(i - 15, i).search(/\[[^\]]*/)
      let charsetEnd = mixedJson.substring(i, i + 15).search(/[^\[]*\]/)
      if (mixedJson[i] == '/' && charsetStart !== -1 && charsetEnd !== -1)
        continue;

      isEscapedObject = null;
      continue;

You can find the file locally in ./node_modules/ytdl-core/lib/utils.js

danisty avatar Apr 26 '23 23:04 danisty

After some research I've found that the problem has to do with the signature deciphering extraction of functions, specifically the extractNCode function, when calling cutAfterJS it fails to escape the following string /[/,-33,/,/]{/,function due to the literal / characters inside a RegEx character set, and so it counts opening and closing brackets incorrectly as it treats most part of the code as a regular expression, resulting in the script not getting to the end of the function and missing a catch block and a return statement.

TEMP FIX Add a check for RegEx character sets, replace

https://github.com/fent/node-ytdl-core/blob/0d3f91b424e81aa79fc2ec021d921d4d21f3e6ef/lib/utils.js#L97-L102

with

  // Go through all characters from the start
  for (i = 0; i < mixedJson.length; i++) {
    // End of current escaped object
    if (!isEscaped && isEscapedObject !== null && mixedJson[i] === isEscapedObject.end) {
      // Ignore character inside RegEx character set with a range of 30 characters
      let charsetStart = mixedJson.substring(i - 15, i).search(/\[[^\]]*/)
      let charsetEnd = mixedJson.substring(i, i + 15).search(/[^\[]*\]/)
      if (mixedJson[i] == '/' && charsetStart !== -1 && charsetEnd !== -1)
        continue;

      isEscapedObject = null;
      continue;

You can find the file locally in ./node_modules/ytdl-core/lib/utils.js

This works for me. I made a patch with this changes, so you can use it with "ytdl-core": "git+https://github.com/dim4ik1106/node-ytdl-core.git#master",

dim4ik1106 avatar Apr 27 '23 12:04 dim4ik1106

To make your code work you can use this patch

"ytdl-core": "git+ssh://[email protected]:khlevon/node-ytdl-core.git#v4.11.4-patch.1"

khlevon avatar Apr 27 '23 14:04 khlevon

UnhandledPromiseRejectionWarning: Error: Could not parse decipher function: TypeError: decipherFuncName.replaceAll is not a function Apr 27 10:07:58 PM at extractDecipher (/opt/render/project/src/node_modules/ytdl-core/lib/sig.js:92:13) Apr 27 10:07:58 PM at Object.exports.extractFunctions (/opt/render/project/src/node_modules/ytdl-core/lib/sig.js:126:3) Apr 27 10:07:58 PM at /opt/render/project/src/node_modules/ytdl-core/lib/sig.js:22:29 Apr 27 10:07:58 PM at runMicrotasks () Apr 27 10:07:58 PM at processTicksAndRejections (internal/process/task_queues.js:95:5)

MeLikeApplez avatar Apr 28 '23 03:04 MeLikeApplez

To make your code work you can use this patch

"ytdl-core": "git+ssh://[email protected]:khlevon/node-ytdl-core.git#v4.11.4-patch.1"

For me this syntax worked:

"ytdl-core": "https://github.com/khlevon/node-ytdl-core.git#v4.11.4-patch.1"

nezort11 avatar Apr 28 '23 07:04 nezort11

To make your code work you can use this patch

"ytdl-core": "git+ssh://[email protected]:khlevon/node-ytdl-core.git#v4.11.4-patch.1"

In case someone needs to have node 12 and 14 support, you can use this patch

"ytdl-core": "git+ssh://[email protected]:khlevon/node-ytdl-core.git#v4.11.4-patch.2"

For more details check this PR: https://github.com/fent/node-ytdl-core/pull/1217 Also, do not hesitate to review the code and write comments or approve it :)

khlevon avatar Apr 28 '23 09:04 khlevon

@Sansekai

provisionally im using https://www.npmjs.com/package/@distube/ytdl-core work for me Try this: "ytdl-core": "npm:@distube/ytdl-core",

Don't forget to add the version number ^4.11.9

"ytdl-core": "npm:@distube/ytdl-core@^4.11.9"

4.11.9 cannot play some streams, I updated to 4.11.10 and it's working normally

npm i ytdl-core@npm:@distube/ytdl-core@latest

fpsone avatar May 24 '23 20:05 fpsone

4.11.5 same issue

npm install khlevon/node-ytdl-core.git#v4.11.4-patch.1 work

ledlamp avatar Jul 29 '23 06:07 ledlamp