Announcements

Help Wizard

Step 1

NEXT STEP

API for finding list of user's playlists song appears in

API for finding list of user's playlists song appears in

Plan: Premium

Country: USA

 

 

My Question or Issue

I'm trying to build a view where I can see a list of a user's playlists that a given song appears in. Currently, the only feasible approach given the existing API is to iterate through a user's playlists, then all of their songs in each of those playlists, until I can find the song in that playlist (at which point I can at least stop fetching more songs from that playlist). This is slower and more cumbersome than I'd like.

In light of the official app's new "add to playlist" screen where you can see each of your playlists, and which playlists that track is currently in, this seems particularly inefficient. What are the chance we can get an endpoint that enables similar functionality? Even an endpoint to check if a song exists in a given playlist would be extremely helpful.

I'm also interested to see if anyone's solved this with a better approach that I'm just missing.

Reply
5 Replies

Did you figure out any better approach? I am trying to do something similar - get all playlists in which a song appears and in which it does not. Also, I wonder making that many requests could trigger rate limits? 

Unfortunately I never found a better way. I really hope this gets added to the public API at some point, cuz this approach makes the UI I'm trying to build almost unusably slow.

The workaround I used is to get all the playlists first, then make concorrent API call for each playlist to fetch all items. My app maitains a local state of every playlist and songs, and I haven't experienced any drastic slowdowns. I was worried if I would be rate limited, but I did not.
I am using the official spotify typescript sdk w/ react by the way.

Keeping it all in state is a good idea (although it kinda feels like a lot of state? I guess if you only fetch the minimal data you need...), I'll have to give that a try. It's been a while since I touched the project, but IIRC I was doing that iterating process as each song came up... Which like, now that you point it out, obviously I should've saved that, I had to go through most of each of a users' playlist every time I did that, might as well at that point. Thanks!

Yeah, iterating approach would be too slow to be useful. Technically, I have six states, but 4 of them are control states, that leaves 2 states: one for list of playlists (array of playlist object), and a tracks, state (array of `{ playlist_id, tracks }`).
I load everything after user logs in, and that state is maintained for all operations until user reloads the page.

Suggested posts