ytmusic-api icon indicating copy to clipboard operation
ytmusic-api copied to clipboard

TypeError in Playlist.js

Open rakuzen25 opened this issue 2 years ago • 8 comments

When I tried to run

const api = new YTMUSIC(
    "cookie",
    { userID: "" },
);
const data = await api.getPlaylist("RDCLAK5uy_k1Wu8QbZASiGVqr1wmie9NIYo38aBqscQ");
console.log(data);

Node exited with an error:

/Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:128
                        album: e.flexColumns[2].musicResponsiveListItemFlexColumnRenderer.text.runs[0],
                                                                                                   ^

TypeError: Cannot read properties of undefined (reading '0')
    at /Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:128:100
    at Array.map (<anonymous>)
    at /Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:112:31
    at step (/Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:52:23)
    at Object.next (/Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:33:53)
    at fulfilled (/Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:24:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.3.0

Any ideas why?

rakuzen25 avatar Jan 04 '23 17:01 rakuzen25

Hello. Please update package to version 0.0.9

"dependencies": {
    "ytmusic": "^0.0.9"
  },

And then you should create API instance like this (for using without cookie):

const api = new YTMUSIC()

It should work, I've tested on my setup.

I will specify this in docs soon.

vladdenisov avatar Jan 04 '23 18:01 vladdenisov

PS: I forgot to publish version, when I've fixed all bugs in october :)

vladdenisov avatar Jan 04 '23 18:01 vladdenisov

Thanks so much for the prompt reply! I'll take a look.

And then you should create API instance like this (for using without cookie):

Does that mean I cannot create an API with cookies now, or does that simply mean I can choose to use or not to use cookies?

rakuzen25 avatar Jan 04 '23 18:01 rakuzen25

Does that mean I cannot create an API with cookies now, or does that simply mean I can choose to use or not to use cookies?

You should be able to use both: anonymous requests and requests, which require a cookie (like creating a playlist).

If anything goes wrong, feel free to open an issue or mention me here!

vladdenisov avatar Jan 04 '23 18:01 vladdenisov

You should be able to use both: anonymous requests and requests, which require a cookie (like creating a playlist).

Hmm, it feels like something isn't right here though:

https://github.com/vladdenisov/ytmusic-api/blob/613a87353adf3688ab14575e690239c5d55571af/index.ts#L11-L14

Shouldn't cookie and userID be optional then? My TS linter keeps calling me out for not specifying userID in the previous version, don't think this got fixed yet.

rakuzen25 avatar Jan 04 '23 18:01 rakuzen25

Yeah, looks odd to me too. For now you can specify blank cookie const api = new YTMUSIC(""). I'll take a look into it a bit later

vladdenisov avatar Jan 04 '23 18:01 vladdenisov

No worries! Please keep up the amazing work - one of the few still-maintained YouTube Music API out there and the only one with full cookies support AFAIC 😁

I have another question related to browser usage but I'll open another issue. Cheers.

rakuzen25 avatar Jan 04 '23 18:01 rakuzen25

You should be able to use both: anonymous requests and requests, which require a cookie (like creating a playlist).

Hmm, it feels like something isn't right here though:

https://github.com/vladdenisov/ytmusic-api/blob/613a87353adf3688ab14575e690239c5d55571af/index.ts#L11-L14

Shouldn't cookie and userID be optional then? My TS linter keeps calling me out for not specifying userID in the previous version, don't think this got fixed yet.

@vladdenisov I'm having an issue with using api.getPlaylists. I'm getting invalid args error. I've tried passing a blank string for userId along with cookie but still gives the error. I tried to search the docs for how to get a user id and authuser but couldn't find it

cmclark00 avatar Feb 01 '24 16:02 cmclark00