Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

How to code to get random song from user from folder from playlist?

How to code to get random song from user from folder from playlist?

Hello ,

 

I am trying to create a code (nodeJS) to get the url of a random song.. This song is picked random from my folder wich contain playlists ( my account>>>Main folder >>> folders of playlists >>> playlists >> Song url (http)

If someone have an idea ?

 

( sorry for my bad english )

Reply
1 Reply

I don't believe there is a way to get the list of playlists from a folder ambiguously, but you could supply node with an array of the uri's of the playlists you want to include. Create a simple for loop that goes through each uri, and gets the tracks for each playlist (you can filter the result using the filter field in the get request)

 

so your get request would look something like this (excluding authorization):

https://api.spotify.com/v1/playlists/YOUR_PLAYLIST_URI_HERE/tracks?fields=items(track(uri))

you'll have to interpret the result of that, but you can add each track's uri to an array. If you do all of this on initialization, it only has to be done once. Then you can pull a random value from the array, giving you the uri of a random track in your list of playlists. 

Suggested posts