Help Wizard

Step 1

NEXT STEP

Spotify Codes - How do they work?

Solved!

Spotify Codes - How do they work?

I am trying to understand how Spotify Codes work technically, and I can't find any information on them. My answer to this question on stack overflow shows some of the digging I've done: https://stackoverflow.com/a/62120952/10703868

 

My question is, how do you map a URI that has 22 characters 0-9a-Z to 21 octal bits of information? How does this 37i9dQZF1DXcBWIGoYBM5M map to this [0, 6, 0, 2, 4, 5, 1, 4, 5, 2, 3, 7, 3, 7, 1, 5, 6, 2, 5, 7, 4, 3, 0]?

 

spotify_playlist_37i9dQZF1DXcBWIGoYBM5M.jfif

Reply

Accepted Solutions
Marked as solution

If you or anyone else is still interested, I asked the question on StackOverflow and someone shared a link to the patent in their answer.  Spotify supposedly does use a look up table to match Codes with their much longer URIs.

View solution in original post

5 Replies

Had a feeling someone would find this too, generating them is easy using that website but to read them is another matter as I was also trying to figure out how these codes work. My thought is although Spotify Ids are base62 encoded it might be they don't need all that headroom.

 

The code is 23 octal bits long, which can encode a sequence of 22 values between 0-7 and another for the type, although it is not consistently one of the values of the code itself from what I've found. The code means you can have 54,875,873,536 artists, and the same number of tracks, playlists etc which is more than enough so this may be the missing clue? I'm also hopeful Spotify will say how these work as it would be useful to know!

 

Edit: Of course the last digit would be check digit so 37,822,859,361 combinations are covered with 21 numbers - is interesting how you fit 16 base-64 characters into 21 octals

I'm glad someone else is interested in this as well! I tried to see if there was a pattern for track/album/artist etc. but I don't see one. Actually, I noticed they don't use the first, 12th, or last octal bit (ends are low, 12 is high).

 

playlist
[0, 3, 3, 0, 5, 2, 2, 2, 2, 5, 1, 7, 0, 0, 5, 6, 0, 7, 7, 7, 1, 5, 0]
[0, 5, 6, 5, 3, 5, 4, 2, 7, 2, 5, 7, 1, 3, 1, 1, 6, 1, 1, 6, 7, 6, 0]
[0, 4, 6, 6, 6, 4, 4, 1, 6, 6, 6, 7, 7, 3, 6, 0, 7, 6, 0, 2, 1, 7, 0]
[0, 0, 3, 3, 7, 5, 2, 3, 1, 1, 4, 7, 5, 5, 5, 3, 3, 7, 5, 1, 4, 3, 0]
tracks
[0, 6, 2, 2, 1, 5, 2, 6, 2, 2, 3, 7, 7, 6, 6, 4, 5, 6, 0, 1, 4, 3, 0]
[0, 7, 7, 1, 4, 7, 1, 0, 4, 7, 1, 7, 6, 5, 6, 3, 1, 6, 4, 4, 7, 7, 0]
[0, 1, 1, 1, 5, 7, 1, 3, 3, 1, 0, 7, 7, 0, 7, 3, 2, 3, 0, 6, 0, 0, 0]
[0, 7, 6, 6, 7, 4, 4, 6, 7, 0, 6, 7, 0, 4, 1, 7, 3, 2, 0, 5, 4, 7, 0]
[0, 0, 0, 6, 1, 3, 3, 2, 2, 0, 2, 7, 3, 2, 4, 1, 6, 0, 1, 5, 0, 4, 0]

 

Indeed was very interested I'd tried to figure them out before but your post re-ignited my interest, even had the pen and paper out to try and figure it out, I'd not noticed the first, last and middle all being the same! So they only use 20 of the octals, I couldn't see any pattern but the number somehow represents the type and the item.

I wrote an app for Groove Music from Microsoft that encoded their GUIDs by shortening them then representing each with numbers and those codes were over 40 characters long, I used OCR to scan them and worked quite well so this code which was shorter got me interested too. I think they could also use this pair system or similar as I represented A with 01, B with 02 and so on so you could represent their code the same way but only the first 8 characters leaving another 2 for the type, or first 9 with one for the type but what the other 7 or 8 are then for or how you'd work those out if true I don't know but maybe will figure it out one day!
Marked as solution

If you or anyone else is still interested, I asked the question on StackOverflow and someone shared a link to the patent in their answer.  Spotify supposedly does use a look up table to match Codes with their much longer URIs.

Thanks @boonpeter, I also had found this post a couple of weeks ago and meant to update this topic for you also!

 

I'm glad you did as one of the other answers since I looked has actually found the endpoint they use to do the lookup itself.

 

I knew there was a lookup table and had to be some way to use it after what you'd posted before. It makes sense they just have a new lookup id for each item which is more than enough to cover every possibility they need still for the Spotify Codes but without the ability to request the lookup it was useless but might be possible now thanks to that answer, although there's some additional encoding of the number used that will need to be figured out however but also just noticed that the scope needs to come from the app so might make it unusable for non-Spotify use because of that

Suggested posts