Androz2091 / discord-player

🎧 Complete framework to simplify the implementation of music commands using discord.js v14
https://discord-player.js.org/
MIT License
589 stars 192 forks source link

Age-restricted YouTube content crashing the bot despite having cookies and ID token. #1904

Closed SimplyJustDanny closed 3 months ago

SimplyJustDanny commented 3 months ago

Describe the bug I have a personal bot that I host on a Replit repository for ease of access anywhere. Age-restricted content being pulled with the YouTube extractor seems to crash the bot entirely, despite having both personal cookies and ID token included in the header. This issue also occurs in my personal backup from VSCode, so it's not a cloud-based issue.

To Reproduce Steps to reproduce the behavior:

  1. Load a YouTube video that is both age restricted and has '&rco=1' at the end (this URL flag disables the "This video may be inappropriate for some user" message and loads the video immediately). Make sure you're logged into an account that can access age-restricted content.
  2. With the browser's Developer Tools, extract the cookie string from the RotateCookiesPage's Request Header in Network and the watch?v='s ID_TOKEN in Sources.
  3. Implement the cookies and ID_TOKEN like shown below (or paste the raw cookie string, my testing showed no differences).
  4. Initiate bot as normal.
  5. Immediately add an age-restricted song or load it into queue (whether or not it has '&rco=1' at the end seems irrelevant, the link the bot generates seems to remove it; it does not seem that I can prevent it from doing so).
  6. Should crash once the song plays.

Expected behavior (ID_TOKEN censored) That the YouTube video be extracted normally or that a more explicit error code were given, but instead it just says that "stream could not be extracted." I was also expecting that the crash occurs when the video is added to the bot in any capacity, but strangely, it gets stored into the queue just fine. Once the bot actually tries playing it, though, it crashes.

Screenshots image image

Please complete the following information:

Additional context I had been trying to resolve this issue for a few weeks now and it seems most of the solutions that I was provided were unfruitful. Cookie implementation seems to match what I checked in the discord-player.js guide, what I checked in other GitHub issues, and what I was informed. in the official Discord for the framework. I was advised to move it here to parse if this correlates to any possible bugs.

twlite commented 3 months ago

@SimplyJustDanny few things to clarify here,

if things don't meet the expectation, it is most likely the youtube library's fault here. We follow a common pattern. Unless we are doing it in a wrong way, discord-player has nothing to do with this issue.

twlite commented 3 months ago

And I see you are using @distubejs' ytdl-core which seems to expect a new cookie format (this might be the problem, plus I am totally okay with it being different from all other alternative youtube libraries as it is scoped to distubejs), it will be harder to keep track of which package uses which format as our goal is to provide singular api for everything. This can be difficult from a user's pov as well. If all these libs expect different format of cookie, I'd like to propose the addition of CredentialManager within discord-player to provide sensitive information such as tokens/cookies to the extractors.

SimplyJustDanny commented 3 months ago

Since you suggested the cookie format being different on distube's ytdl-core, I tried switching over to the basic one with youtube-ext to see if it's just an extractor problem, but the issue persists. Then I considered changing other packages like opus libraries, but that didn't seem to fix it either. I also tried updating discord-player to 6.6.8, but the songs couldn't even load. I understand that the issue is no longer the focus, but something I thought worth mentioning just in case. Thanks for the response either way.

twlite commented 3 months ago

This part needs a rework as it is confusing to interpret. For the time being, you should be able to pass json format of cookie just fine, but you may get typescript errors. Agent is automatically created when cookie is available. In other words, new format of cookie works with this youtube lib.

I am closing this issue in favor of https://github.com/Androz2091/discord-player/issues/1905