I sorted 3,472 liked songs by how they feel
My Liked Songs is one long list: Persian rap next to lo-fi next to film scores. I wanted playlists by mood, not by genre and not by the day I liked something, so I built a small local app that listens to every song and sorts them for me.
The problem
Spotify used to hand out this data. Since late 2024, new apps get neither audio features (valence, energy, danceability) nor 30 second previews. So the app has to find the audio itself and judge the mood itself. And mood is harder than genre: a sad song and a happy song can share every instrument.
How it works
- Find the audio. A 30 second preview from Deezer or iTunes, and for most songs the full track. More on both below; this was most of the work.
- Score the mood. Essentia's models give every song 14 scores (happy, sad, relaxed, aggressive, party, danceable, dark, acoustic, electronic, instrumental, engaging, approachable, valence, arousal) plus an embedding of the sound itself. Essentia's model package has no Windows build, so the app runs its ONNX models with ONNX Runtime on a NumPy rebuild of its audio front end, which matches the original within 0.0003.
- Find the moods. KMeans on the 14 scores, with valence and arousal counting double and a smaller dose of the sound embedding, so groups follow feeling first and sound second. I tried 25 and 40 groups, listened through them, and settled on 24, each named after its most typical songs.
- Keep the playlists tight. A song far from its mood's centre is left out instead of forced in. At my setting that is 456 songs. The rest went to Spotify as 24 playlists, with songs that sit between two moods in both.
Getting the audio
Matching previews
The first version looked each song up on Deezer by its ISRC (the recording's ID)
and fell back to Deezer's strict search, artist:"…" track:"…". That
fallback returned nothing for every single query, and my title cleanup wiped
Persian and Cyrillic titles to empty strings. So 29% of the library (1,020
songs) came back without audio. What fixed it:
- Plain searches, two sources. Artist and title as free text on Deezer, then the iTunes Search API for what Deezer doesn't have. A hit only counts if title, artist and length all match; in a check of 79 hits, all 79 were the right song.
- Matching that survives other scripts. Unicode normalization, Cyrillic to Latin, and a similarity threshold instead of exact equality, so a Cyrillic title can match its Latin spelling and a small spelling difference doesn't lose a song.
- Downloads that don't give up. Deezer's preview server answers bursts with HTTP 429, which had saved 38 songs as empty files. Paced retries, and trying the next source when one fails, fixed that: in a test, 10 of 10 came back.
- A reason for every miss. Of the 334 songs that still have no preview, 228 were taken down from Deezer, 44 were never there and 24 are blocked in my country, and none of those is on iTunes either. The other 38 are the failed downloads from before the fix.
That took the songs without a preview from 29% to under 10%.
30 seconds is not the song
A preview is usually the chorus, and Deezer and iTunes use the same 30 seconds (31 of 32 songs I compared). Clip quality was not the problem: re-encoding at Deezer's 128 kbps moved the mood scores by about 3% of the gap between two random songs. The excerpt was. In a 50 song test, analysing the whole song moved 4 in 10 songs to a different group.
So the app finds each song on YouTube Music by its title (including words like live, remix or slowed), artists, album and length, downloads it, and checks it is the same recording by finding the preview inside it. Then it analyses the full song and deletes the file. My first version took 7 seconds per song. One search request on YouTube Music's own catalogue, one download step and three songs at a time got that to about 1 second, a bit over an hour for the library. 2,929 songs were analysed whole, including 59 that had no preview, 36 of them the failed downloads. 275 songs still have no audio at all.
The result
This is the app's own view, exported as one HTML file. Every dot is a song, placed from sad to happy and from relaxed to aggressive. Click a playlist under the map to pin it, hover a dot to see the song, and press ▶ on any card to play it.
Open it full screen ↗ Songs play through Spotify's player: log in to Spotify for full songs, otherwise you get 30 second previews.
How many songs made it through each step:
| Step | Songs | Lost or gained, and why |
|---|---|---|
| Liked on Spotify | 3,559 | |
| Counted once | 3,472 | 87 were liked twice: the single and the album version, or a re-release |
| Found a 30 second preview | 3,138 | 2,815 by ISRC, 227 by Deezer search, 96 on iTunes. 334 without one |
| Analysed | 3,197 | YouTube Music added 59 songs with no preview. 275 have no audio anywhere |
| Grouped into 24 moods | 3,197 | every analysed song gets a group |
| In a playlist | 2,741 | 456 left out because they sit too far from every mood. 3,228 playlist spots, since songs between two moods are in both |
Where it works less well
To my ear, the clustering is weaker on Persian and Kurdish songs overall and makes more mistakes there. The mood models were most likely trained mostly on Western music, so their scores for other traditions are less reliable.
A few other things I fixed along the way
- 87 songs were liked twice (single and album version, re-releases). They now count once.
- Valence and arousal put metal on the happy side, so the map uses the happy, sad, relaxed and aggressive scores instead.