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

Multiple JSON page requests made before falling back to watch page #815

Closed
benkaiser opened this issue Dec 8, 2020 · 5 comments
Closed

Comments

@benkaiser
Copy link

Created a comment on the relevant line here: 60cdb41#r44919269

Basically it appears that the token logic is setting a promise to the cache rather than the actual value now. As a result I'm seeing ytdl make a bunch of json requests all with "reload now" responses before finally falling back to the watch page.

It does eventually resolve with the right information, but it's causing the performance to be sub-par (~several seconds for getInfo).

Here is a network trace with the current logic:

First request:
image
Second request:
image

And by updating getIdentityToken to this: (basically don't use cookieCache.getOrSet, actually make it a promise and cookieCache.set in the later part of the promise):

const getIdentityToken = async (id, options, key, throwIfNotFound) => {
  let page = await getHTMLWatchPageBody(id, options);
  let match = page.match(/(["'])ID_TOKEN\1[:,]\s?"([^"]+)"/);
  if (!match && throwIfNotFound) {
    throw new UnrecoverableError('Cookie header used in request, but unable to find YouTube identity token');
  }
  exports.cookieCache.set(key, match && match[2]);
  return match && match[2];
};

First request:
image

Second request:
image

benkaiser referenced this issue Dec 8, 2020
sometimes when clearing the ytdl-core internal cache, the app would
still hang, waiting for any entries in the cache to expire.
@fent
Copy link
Owner

fent commented Dec 8, 2020

the json endpoint returning {"reload":"now"} started happening about 1 to 2 weeks ago. it's not related to the cache returning a promise. the identity token request happens after the json request, when it previously wasn't needed since we'd get a good reply on the first request

@benkaiser
Copy link
Author

benkaiser commented Dec 9, 2020

@fent surely we aren't intending on passing a header with [object Promise] as the value though?

image

@fent fent added the bug label Dec 10, 2020
@fent fent closed this as completed in eb42b9c Dec 17, 2020
@github-actions
Copy link

🎉 This issue has been resolved in version 4.1.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@benkaiser
Copy link
Author

Hey @fent, I think we need to revisit. I'm still seeing promises being sent in the x-youtube-identity-token.

Would you be open to my submitting a pull-request to fix?

@TimeForANinja
Copy link
Collaborator

fent is currently taking a bit of a break
but if you manage to fix it a PR is always welcome 😉
it's a good start for a discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants