getInfo giving me 'Invalid or unexpected token' error
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.
Also getting this error from two different bots, one of which I only use for testing. So not likely rate limiting.
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?
downgrading to 4.9.1 fixes for me
ok sir thanks a lot, it really helps for a while now
downgrading to
4.9.1fixes for me
Can confirm that this fixes the issue.
Also confirming that this temporarily fixes it for me too.
Throttled to about 10mb a minute but its a good temporary fix. Much appreciated!
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 Thanks for looking into this, FYI you've got a typo on line 3 of your fix, index should be ndx.
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
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%.
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
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.
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.
Go to
node_modules/@distubedeleteytdl-corefolder then open cmd and type this commandnpm i [email protected]. Go tonode_modulesand copyytdl-corefile and paste it intonode_modules/@distubeIt works 100%.
installing @distube/[email protected] (deprecated version) works well without moving anything
Thank you!
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"
Version 4.11.0 is working for me again