zS1L3NT / ts-npm-ytmusic-api

A type-safe and basic YouTube Music API wrapper
https://npmjs.com/package/ytmusic-api
GNU General Public License v3.0
81 stars 17 forks source link

[QUESTION]: Where/how to generate auth cookies? #39

Closed isaachinman closed 3 weeks ago

isaachinman commented 3 months ago

Please describe the current behaviour of the code.

-

Please describe the expected behaviour of the code.

-

What are the steps to reproduce the error?

-

Additional Information

Discussions are not enabled on this repo, so I was forced to open an issue. Apologies.

I am just getting started with this SDK and want to authenticate calls based on premium YTM accounts.

The initialize method looks like this:

initialize(options?: {
    cookies?: string;
    GL?: string;
    HL?: string;
}): Promise<this | undefined>;

How should one generate cookies?

Update:

I have grabbed the SAPISID value from the YTM web app.

After inserting this into client initialisation, I get an error:

SyntaxError: Invalid RegExp: Invalid escape

The error points to a line in your zod-to-json-schema dep.

Update 2:

The regex problem seems to be some sort of React Native incompatibility issue. Please ignore.

Next problem:

this.config.INNERTUBE_API_VERSION is undefined. Leading to API reqs to URLs like: https://music.youtube.com/youtubei/undefined/browse?alt=json&key=undefined

I am grabbing the cookies by checking a 200 req in devtools on the YTM web app, copy/pasting the cookie value directly into this package.

Clearly the cookies are failing to be parsed or to authenticate the reqs, but it's not at all clear to me why.

It seems strange that your documentation offers no explanation as to how cookies should be obtained, as if all users would somehow already know...

Yoda-Soda commented 3 weeks ago

Have a look at the python implementation docs: https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html