distubejs / ytdl-core

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

Cannot destructure property 'jar' of 'options.agent' as it is undefined #62

Closed Brainicism closed 3 months ago

Brainicism commented 3 months ago

Describe the bug

getInfo calls are failing. Is passing an agent with cookies required now? Requiring this by default seems to be a pretty major breaking change, given that most people probably use this library unauthenticated.

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

Seems introduced by https://github.com/distubejs/ytdl-core/commit/6ddf70d8d74ba73ea434dd085357989648340883

Debug File

Environment

skick1234 commented 3 months ago

It is included as a default option, but I cloned options object in getBasicInfo so it won't be passed to getInfo options. It should be resolved now.

Brainicism commented 3 months ago

Getting the same error but in a strange way. If I call getBasicInfo() or getInfo() independently, they will succeed. But if I call either of them one after the other, I still receive the same error as above.

My use-case was, calling getBasicInfo() to check if a video was playable, followed by a ytdl() call to begin downloading, which internally calls getInfo(), which is failing.

I'm assuming this is because getBasicInfo() is supposed to fill the default options (including agent), but the call is being skipped because of the info cache.

node ➜ /workspace (update-ytdl) $ npx ts-node src/ytdl-test.ts 
/workspace/node_modules/@distube/ytdl-core/lib/info.js:322
  const { jar, dispatcher } = options.agent;
          ^
TypeError: Cannot destructure property 'jar' of 'options.agent' as it is undefined.
    at fetchIosJsonPlayer (/workspace/node_modules/@distube/ytdl-core/lib/info.js:322:11)
    at exports.getInfo (/workspace/node_modules/@distube/ytdl-core/lib/info.js:247:35)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    (async () => {
    const x = await ytdl.getBasicInfo(
        "http://www.youtube.com/watch?v=aqz-KE-bpKQ",
    );

    const y = await ytdl.getInfo("http://www.youtube.com/watch?v=aqz-KE-bpKQ");
})();

Created new issue for this here: https://github.com/distubejs/ytdl-core/issues/63