distubejs / ytdl-core

YouTube video downloader in javascript.
MIT License
206 stars 43 forks source link

Cannot destructure property 'jar' of 'options.agent' #59

Closed Lampropoulosss closed 1 month ago

Lampropoulosss commented 1 month ago

Describe the bug

I am trying to get the webm audioonly version of a video and I get the following error

TypeError: Cannot destructure property 'jar' of 'options.agent' as it is undefined.
   at fetchIosJsonPlayer (/root/mp3converter/node_modules/@distube/ytdl-core/lib/info.js:320:11)
   at exports.getInfo (/root/mp3converter/node_modules/@distube/ytdl-core/lib/info.js:245:35)
   at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Debug File

const ytdl = require("@distube/ytdl-core");

const stream = ytdl(ytdl.getVideoID(req.query.video), {
  filter: "audioonly",
  format: "webm",
  // IPv6Block: "2001:2::/48",
  requestOptions: {
    headers: {
      "User-Agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0",
    },
  },
}).on("error", (error) => console.log(error));

Environment

Lampropoulosss commented 1 month ago

Even if I comment out the requestOptions, the issue persists.

skick1234 commented 1 month ago

Your code is working on my PC, maybe due to your node.js version I guess. I'm using 20.16.0. Anyway, you can add an agent manually with agent: ytdl.createAgent() option.

const stream = ytdl(ytdl.getVideoID(req.query.video), {
  agent: ytdl.createAgent(),
  ...
})
Lampropoulosss commented 1 month ago

Works now, thank you!