Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default options not applied when getInfo() is called consecutively with same video ID #63

Closed
Brainicism opened this issue Aug 5, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@Brainicism
Copy link

Brainicism commented Aug 5, 2024

Describe the bug

getInfo() calls getBasicInfo()

exports.getInfo = async(id, options) => {
  const info = await exports.getBasicInfo(id, options);

But the result of both getInfo() and getBasicInfo() are cached with the video ID as the cache key

for (let funcName of ['getBasicInfo', 'getInfo']) {
  /**
   * @param {string} link
   * @param {Object} options
   * @returns {Promise<Object>}
   */
  const func = exports[funcName];
  exports[funcName] = async(link, options = {}) => {
    utils.checkForUpdates();
    let id = await urlUtils.getVideoID(link);
    const key = [funcName, id, options.lang].join('-');
    return exports.cache.getOrSet(key, () => func(id, options));
  };
}

This causes issues because getBasicInfo() performs mutations on the ytdl options passed in by the user. When getBasicInfo() is already cached, it isn't invoked, and the mutations on options are not performed. Some of these mutations include

  utils.applyIPv6Rotations(options);
  utils.applyDefaultHeaders(options);
  utils.applyDefaultAgent(options);
  utils.applyOldLocalAddress(options);

In my case, this is causing the default agent to be missing.

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)

Minimal repro:

(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");
    // or ytdl(`https://www.youtube.com/watch?v=aqz-KE-bpKQ`);
})();

Debug File

Environment

  • @distube/ytdl-core version: 4.14.1
  • Node.js version: v18.20.3
  • Operating system: Debian GNU/Linux 11
@kevinrss01
Copy link

Same here 👋

@kevinrss01
Copy link

Did you find a workaround? @Brainicism

@Brainicism
Copy link
Author

You can just provide the default agent when passing in the options

const stream = ytdl(ytdl.getVideoID(req.query.video), {
  agent: ytdl.createAgent(),
  ...
})

@skick1234
Copy link

I forgot that ytdl-core has a cache system .-. Will fix it when I get home

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants