distubejs / ytdl-core

YouTube video downloader in javascript.
MIT License
289 stars 50 forks source link

TypeError: Cannot read properties of undefined (reading 'videoId') #61

Closed mr-flame7892 closed 3 months ago

mr-flame7892 commented 3 months ago

Describe the bug

When I try to get informations about a video on my hosting machine, it returns me the following error:

TypeError: Cannot read properties of undefined (reading 'videoId')
    at fetchIosJsonPlayer (/home/container/node_modules/@distube/ytdl-core/lib/info.js:342:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async exports.getInfo (/home/container/node_modules/@distube/ytdl-core/lib/info.js:245:29)

I also tried to get these informations on my computer (which runs on windows 11) and unlike my hosting machine, it worked perfectly. I first thought that was an issue with the node version but my computer has the same node version therefore it's not that. And this bug happens on every video that I'm trying to get info.

Debug File

const fs = require('fs');
const ytdl = require("@distube/ytdl-core");
const agent = ytdl.createAgent(JSON.parse(fs.readFileSync("agent.json")));
await ytdl.getInfo("https://www.youtube.com/watch?v=uu2XSQgdQDY", { agent })

Environment

skick1234 commented 3 months ago

Can you update to 4.14.1, then log the error.response to know why it happens?

await ytdl.getInfo("https://www.youtube.com/watch?v=uu2XSQgdQDY", { agent }).catch(e => {
    console.error(e);
    console.log(e.response)
})
mr-flame7892 commented 3 months ago

Can you update to 4.14.1, then log the error.response to know why it happens?

await ytdl.getInfo("https://www.youtube.com/watch?v=uu2XSQgdQDY", { agent }).catch(e => {
    console.error(e);
    console.log(e.response)
})

Now it returns me this:

Error: Malformed response from YouTube
    at fetchIosJsonPlayer (/home/container/node_modules/@distube/ytdl-core/lib/info.js:345:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async exports.getInfo (/home/container/node_modules/@distube/ytdl-core/lib/info.js:247:29) {
  response: {
    responseContext: {
      visitorData: 'CgsyMmNITkhMdlhSNCjEuMC1BjIKCgJERRIEEgAgKjoMCAEg9vCdrsaIh9hm',
      serviceTrackingParams: [Array],
      maxAgeSeconds: 0
    },
    playabilityStatus: {
      status: 'LOGIN_REQUIRED',
      reason: 'Sign in to confirm you’re not a bot',
      errorScreen: [Object],
      skip: [Object],
      pictureInPicture: [Object],
      contextParams: 'Q0FFU0FnZ0I='
    },
    trackingParams: 'CAAQu2kiEwi6puzay9yHAxWK6U8IHYQoDm4=',
    onResponseReceivedEndpoints: [ [Object] ],
    onResponseReceivedActions: [ [Object] ],
    adBreakHeartbeatParams: 'Q0FBJTNE',
    frameworkUpdates: { entityBatchUpdate: [Object] }
  }
}
{
  responseContext: {
    visitorData: 'CgsyMmNITkhMdlhSNCjEuMC1BjIKCgJERRIEEgAgKjoMCAEg9vCdrsaIh9hm',
    serviceTrackingParams: [ [Object], [Object], [Object], [Object] ],
    maxAgeSeconds: 0
  },
  playabilityStatus: {
    status: 'LOGIN_REQUIRED',
    reason: 'Sign in to confirm you’re not a bot',
    errorScreen: { playerErrorMessageRenderer: [Object] },
    skip: { playabilityErrorSkipConfig: [Object] },
    pictureInPicture: { pictureInPictureRenderer: [Object] },
    contextParams: 'Q0FFU0FnZ0I='
  },
  trackingParams: 'CAAQu2kiEwi6puzay9yHAxWK6U8IHYQoDm4=',
  onResponseReceivedEndpoints: [
    {
      clickTrackingParams: 'CAAQu2kiEwi6puzay9yHAxWK6U8IHYQoDm4=',
      elementsCommand: [Object]
    }
  ],
  onResponseReceivedActions: [
    {
      clickTrackingParams: 'CAAQu2kiEwi6puzay9yHAxWK6U8IHYQoDm4=',
      startEomFlowCommand: [Object]
    }
  ],
  adBreakHeartbeatParams: 'Q0FBJTNE',
  frameworkUpdates: { entityBatchUpdate: { mutations: [Array], timestamp: [Object] } }
}
TypeError: Cannot read properties of undefined (reading 'videoDetails')
    at Object.execute (/home/container/slash_commands/play.js:194:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.execute (/home/container/events/interactionCreate.js:116:17)
skick1234 commented 3 months ago

Thanks for your response, I will throw a better error message in the next update. Anyway, you ip has been restricted and you have to use cookies to fix it, refer #21

mr-flame7892 commented 3 months ago

It seems that using an older version of ytdl-core solves the issue (I downgraded to the version 4.13.7)