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

Getting a random track/ generating a valid random track ID

Getting a random track/ generating a valid random track ID

I would like to create a tool that generates a truly random Spotify song, but cannot find out how this could be done. I've considered two possible approaches, which come with the following questions:

 

1. Is there/will there be a way of getting a random track from the API? I went through the reference, and using the "Get Recommendations" call from the browse API with random genre seeds seemed the most promising, but as the documentation states, it does not handle obscure music well.

 

2. Another approach would be to generate a random track ID on the application side, then use a get requests for that track. However, I cannot seem to find a pattern for the track IDs that would allow me to generate a random valid one. Are the track IDs simply randomly generated, with no way to reproduce them? Or is there a way to consistently generate valid track IDs?

 

Any help would be appreciated.

Reply
1 Reply

Hey! I had the same question a few months ago before a developed Randify, a random Spotify playlist generator. In order to get the random songs I tried multiple things, a few that worked ok where the following:

- Use the API function Search with the q parameter "%25a%25" or using any other random letter instead of a. That will get you the songs that have an a in their name. You can then set the offset parameter to a random number and you will get one of the 1000 songs that you get with the search function. The problem with that is that the search function will sort the music by how many people listen to the songs and will only show popular music.

- In order to solve the "popular music" problem I thought that the best option was to get a songs database and using the same search function, add the song name as the q parameter, therefore the search will be more specific and will find non-popular results. The database I used was MusicBrainz, which has up to 30 million songs. I still used a random offset parameter and had to check if the song was in Spotify (not all songs in the database are in Spotify) before I added it to the playlist. It worked quite good and I'm really proud of the outcome.

Suggested posts