

The URI is 22 characters long, and contains 0-9 a-z A-Z.
Spotify music codes code#
The weird thing about this is the amount of information in the URI and the spotify code do not match up. Using this (sort of messy Python) code I can grab the octal sequence from the barcode image: from skimage import ioįrom skimage.filters import threshold_otsuįrom asure import label, regionpropsįrom lor import label2rgb, rgb2grayīar_dims = īar_dims.sort(key=lambda x: x, reverse=False) In the image above, the max height is 96 pixels, and the bars fall into 8 different height bins. The logo is the max height, and the first and the last bars are always the lowest height. The bars in Spotify Codes have 8 different heights they can be. The code for the above URI looks like this:Īs you noted, they encode the information in the heights of each of the bars, in the same way that the United States Postal Service does in their barcodes (see Intelligent Mail barcode).

If you visit Spotify Codes you can generate a code from the URI. Spotify has URIs for each song, album, artists, user, playlist, etc. I have been digging into Spotify Codes some to try and understand them.

To summarize, they use an intermediate look-up-table to link the barcode to the unique Spotify ID. Update: I asked a similar question and it was answered by someone linking the patent for this barcode. There is no direct mapping between the string "Coffee" and the graphical code you see on your screen. Most likely, Spotify is assigning a unique number to each song, and then encoding that number. Just treat the string as a base-26 number and do the conversion. If you just want to uniquely encode all possible, you can do that with just 23 bits. Given the letters a-z, there are 11,881,376 possible 5-character strings. Even if it can, I can always find a longer song title. For example, there's a song by Pink Floyd called "Several Species of Small Furry Animals Gathered Together in a Cave and Grooving with a Pict." Your encoding algorithm probably won't be able to fit that into 24 bars.

Second, song names can be arbitrarily long. You want the code to uniquely identify the song. That assumption is almost certainly incorrect.įirst, consider what would happen if there are two different songs called "Coffee." Your proposed algorithm would assign them both the same code. It appears that you're making the assumption that there is a direct mapping from the string "Coffee" to the graphic that's shown. I hope somebody can help me improve my small algorithm. Īfterwards I'm using the result array above and find the matches in my Key-array below and get the indexes (10 different indexed -> 10 different possibilities) and use them as bar-sizes.īut, There MUST BE a way more efficient method to translate a string into a unique pattern. I' converting my string 'hello' to binary format and splitting the string up into groups of maximum 3 to get something like this. This is my code I've developed till now, but in this code I used a key-array that includes 10 different possibilities (-> bar sizes), but I just like to us 4 different sizes. What's a good method / easy way to translate a string ( lets say 5 characters) into a unique pattern, that afterwards is also convertible back and read as a string? So let's say there is a row that is divided into 24 bars and all of the bars can have the size '3', '5', '7' or '9'. The Spotify codes - I've already mentioned above - are structured in a row that is divided into different sized bars. I would be super interested in the extent to which it is possible to implement something like this pattern-encryption in javascript. Ok, Im wondering how's the string encryption e.g. However, the question itself was in my opinion not that bad, so I decided to ask a hopefully better version of this question again. Because the question was not formulated that well it was downvoted just instantly. Yesterday I've read the question Algorithm to create costum Template/Code from String.
