How to handle loading spotify playlists with > 100 items?
When loading music using the following query snippet, it only loads the first 100 songs of a spotify playlist. If i recall this is because the spotify api paginates. Does moonlink handle this pagination?
Thank you in advance!
46 Replies
GitHub
moonlink.js/src/typings/Interfaces.ts at v4 ยท Ecliptia/moonlink.js
MoonLink.js is a simple package for lavalink client, perfect for you to create your discord bot with songs, and very simple and easy to use. - Ecliptia/moonlink.js
If you are using source inside the package you have these limitation options
But if it is lavasrc, there is no limitation on the client side, you must configure it on the server side, I don't know if there is a limitation, if not, in the next version I will provide these limitations
But server will anyway load all tracks
I've tried setting those earlier, however that didn't seem to impact anything. I'll try again with lower values to see if there are any limits.
I'm not sure which spotify endpoint moonlink uses. When trying the following endpoint, the limit is 100
https://developer.spotify.com/documentation/web-api/reference/get-playlists-tracks
setting the limit to 101 there throws an error
Just checked
with the following configuration
It still only loads 100 tracks.
Note i forgot to add in the previous message, i'm not using LavaSrc since i don't entirely know how to set it up (yet)
if you're running lavalink yourself, I can send an application.yml for LavaSrc and it's config
not sure if there's much to configure though, there's an
albumLoadLimit
and playlistLoadLimit
, not sure if there's a track limit this way. I believe I've queued playlists with 100+ songs, I can test it outI am self-hosting, and have a plugin installed being the youtube plugin.
I test using the following playlist: https://open.spotify.com/playlist/3FUdwRUWLSujV4dfynUYaw?si=1440e613de7745eb
Spotify
Kalm
I'll add the command structure here:
However it is 4am here at this point, so will likely be signing off soon.
From what i've understood when using LavaSrc, you also need to query differently, or am I wrong there?
GG @MaxTechnics, you just advanced to level 1!
it should be the same, as spotify isn't actually used to play songs though, they will all be queued through another source
it did queue fine for me

I am aware that spotify streams are impossible. But it matches (most often with youtube) instead
Perhaps its a limitation in the default matching algorithm, maybe it does not handle the pagination?
possibly, with LavaSrc though it seems to handle fine. So it may be worth trying. I don't believe you'd have to change any of your code either
I also am using a spotify clientID & clientSecret, so that could be why I don't have issues
So am i, though not on the lavalink side
Thank you for the pointers and setup!
I'll be looking into it first thing tomorrow. and will get back to the post here
yeah no problem, I'm guessing you may be right, could be an issue with the pagination currently
Last I worked directly with the Spotify api was in 2021 (trying to actually pull audio from their service, which of course was impossible). Which led me to believe the 100 song limit was pagination related.
I did expect it to error when setting the Moonlink Manger config to invalid limits (like 100+), maybe there are some protections against it?
I haven't done much with the spotify api directly, I'd have to test it out. I can try to see if there are any limits though
The link in my first post to the docs has a built in little playground to interact with the api
huh, I see what you mean
yeah, the direct API call cuts off at 100 exactly
Reddit
From the learnpython community on Reddit: Spotify API 100 Track Limit
Explore this post and more from the learnpython community
I've tried the application.yml you provided. I got all the tokens put in, however the player still only loads 100 tracks.
I'll be looking into some docs to see if code modifications are required
Code your own spotify playlist fetcher and use it to get playlist data , then send the info to lavalink..
this works ig
That would work, though isn't it better to implement the pagination in moonlink itself? I'll try it later today
this way you can save your playlist too soo no need to get link everytime.. idk if its possible with moonlink/lavalink
I know moonlink supports database storage, though haven't looked into that myself either
GG @MaxTechnics, you just advanced to level 2!
oh i didn't know that...
i use this setup no issues so far.. tested with playlist having 1k+ songs works fine
I tried it and it does in fact work, Though it would be cool to see this handling in moonlink itself.
btw is there any limit to how many songs i can queue ??
I don't think so, as long as you respect api ratelimits
hmm
i use custom queue in my bot .. planning to switch to inbuilt queue
i am currently migrating to moonlink from lavaclient
And trying to recreate the feel of groovy bot

what I find strangest
It's because it's not splitting.
I took a quick look at the source in moonlink, it does not seem to have any pagination logic.
How do you query the playlist in your bot? The standard manager.search does not fix the 100song issue. Im suspecting it does not make use of lavasrc
How do you query the playlist in your bot? The standard manager.search does not fix the 100song issue. Im suspecting it does not make use of lavasrc
I don't use it, and there is logic, when the songs are searched, it does a split of 0, the limit defined in all that loads as playlists in spotify, I just reinforced to do a global
I see, wouldn't it make sense to have pagination on the endpoints that do that though?
Not sure how the other endpoints differ
Yes, the Spotify endpoint delivers per page
This logic is a bit strange indeed.
But I'll do it by track, for me it's better than counting Spotify pages without understanding correctly
I think the api endpoint's response has all that info included, as well as the url for the next page
next
and previous
are endpoint urls for next pages.
I don't think it'd be too complicated to check if (next) Loadfrompage(next)

Now I understand, I'll commit and correct it
If you'd like i can test before you release
Solution
Not that Iโm aware of
Just switched back to release, and can confirm that loading now works as expected.
So for those reading, make sure to update to https://github.com/Ecliptia/moonlink.js/releases/tag/v4.60.4 or later.
To all here, thank you very much for your help and the quick update!
GitHub
Release v4.60.4 ยท Ecliptia/moonlink.js
What's Changed
Add qodana CI checks by @qodana-cloud[bot] in #162
sync: v4 with dev by @1Lucas1apk in #163
sync: v4 with dev by @1Lucas1apk in #164
Full Changelog: v4.52.2...v4.60.4
โจ New Fea...