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

getInfo giving me 'Invalid or unexpected token' error

Open depresif opened this issue 4 years ago • 37 comments

Trying to get the video information from ytdl.getInfo() but I get SyntaxError: Invalid or unexpected token instead. Yes, I am using the latest version of ytdl-core.

Getting data via this code:

const videoData = await ytdl.getInfo(url); // url is: https://www.youtube.com/watch?v=SPzumRExEqw

Error that I am getting:

rma=function(a,b,c,d){var e=null;switch(b){case "JSON":try{var f=c.responseText}catch(h){throw d=Error("Error reading responseText"),d.params=a,bu(d),h;}a=c.getResponseHeader("Content-Type")||"";f&&0<=a.indexOf("json")&&(")]};Yka(ncode);
                                                                                                                                                                                                                             ^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
    at new Script (node:vm:100:7)
    at Object.exports.decipherFormats (C:\Users\null\Desktop\yt-clips\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 (C:\Users\null\Desktop\yt-clips\node_modules\ytdl-core\lib\info.js:401:17)

It happened after getting data of the url approx 20 times, am I getting ratelimited? Thank you.

depresif avatar Aug 11 '22 18:08 depresif

Also getting this error from two different bots, one of which I only use for testing. So not likely rate limiting.

rjarmon avatar Aug 11 '22 18:08 rjarmon

It started happening for me after about 6pm (GMT+1) today. Guessing base.js got updated and broke detection? Do we have a work around in the meantime?

JackReevies avatar Aug 11 '22 18:08 JackReevies

downgrading to 4.9.1 fixes for me

davidkhierl avatar Aug 11 '22 18:08 davidkhierl

ok sir thanks a lot, it really helps for a while now

bangnopal avatar Aug 11 '22 18:08 bangnopal

downgrading to 4.9.1 fixes for me

Can confirm that this fixes the issue.

alierturan avatar Aug 11 '22 19:08 alierturan

Also confirming that this temporarily fixes it for me too.

rjarmon avatar Aug 11 '22 19:08 rjarmon

Throttled to about 10mb a minute but its a good temporary fix. Much appreciated!

JackReevies avatar Aug 11 '22 19:08 JackReevies

https://github.com/fent/node-ytdl-core/blob/11103be3ab373551bddd0938bc0bbaea033acb8e/lib/sig.js#L63-L67

if (ndx >= 0) {
    const end = body.indexOf('.join("")};', ndx);
    const subBody = body.slice(ndx, end);

    const functionBody = `${subBody}.join("")};${functionName}(ncode);`;
    functions.push(functionBody);
}

A temporary fix until someone finds a better solution.

WaqasIbrahim avatar Aug 11 '22 21:08 WaqasIbrahim

@WaqasIbrahim Thanks for looking into this, FYI you've got a typo on line 3 of your fix, index should be ndx.

absidue avatar Aug 11 '22 22:08 absidue

Hi, does one of the forks provide reasonable performance compared to downgrading to version 4.9.1, which takes about 20 times as long? Please feel free to speak with me

ShlomoCode avatar Aug 11 '22 23:08 ShlomoCode

Go to node_modules/@distube delete ytdl-core folder then open cmd and type this command npm i [email protected]. Go to node_modules and copy ytdl-core file and paste it into node_modules/@distube

It works 100%.

ZyadAlnaim avatar Aug 12 '22 00:08 ZyadAlnaim

downgrading to 4.9.1 fixes for me

Downgrade to 4.10.0 for me working too

gohellp avatar Aug 12 '22 01:08 gohellp

thanks for all the info on this. still facing a new minor issue where a bot is disconnecting without logs but most likely a code issue on my part

xWass avatar Aug 12 '22 03:08 xWass

Here's a proper patch from @WaqasIbrahim's changes:

--- a/lib/sig.js
+++ b/lib/sig.js
@@ -63,5 +63,7 @@
       if (ndx >= 0) {
-        const subBody = body.slice(ndx + functionStart.length);
-        const functionBody = `var ${functionStart}${utils.cutAfterJSON(subBody)};${functionName}(ncode);`;
+        const end = body.indexOf('.join("")};', ndx);
+        const subBody = body.slice(ndx, end);
+        
+        const functionBody = `${subBody}.join("")};${functionName}(ncode);`;
         functions.push(functionBody);
       }

This worked for me, applied inside the node_modules/ytdl-core folder.

MCJack123 avatar Aug 12 '22 03:08 MCJack123

In older versions, the sound may cut off in the middle. I don't know the cause. Please let me know if there is a workaround. Or tell me the newest version that works. I am currently downgrading to 4.10.0.

ghost avatar Aug 12 '22 05:08 ghost

Go to node_modules/@distube delete ytdl-core folder then open cmd and type this command npm i [email protected]. Go to node_modules and copy ytdl-core file and paste it into node_modules/@distube

It works 100%.

installing @distube/[email protected] (deprecated version) works well without moving anything

alighamdan avatar Aug 12 '22 05:08 alighamdan

Thank you!

ghost avatar Aug 12 '22 05:08 ghost

npm i [email protected]

It worked for me! Thank you 🤞

sajjadmrx avatar Aug 12 '22 06:08 sajjadmrx

if you install [email protected] (and use distube) and the issue still there execute this command: it will install distube + ytdl-core + @distube/ytdl-core with 4.9.2 version and remove old files then copy the @distube/ytdl-core into node_modules/distube/node_modules/@distube rm -rf "node_modules/distube" && rm -rf "node_modules/@distube/ytdl-core" && rm -rf "node_modules/ytdl-core" && npm i distube @distube/[email protected] [email protected] && rm -rf "node_modules/distube/node_modules/@distube/ytdl-core" && cp -R "node_modules/@distube/ytdl-core" "node_modules/distube/node_modules/@distube/ytdl-core"

alighamdan avatar Aug 12 '22 07:08 alighamdan

Version 4.11.0 is working for me again

omenocal avatar Aug 12 '22 17:08 omenocal