Add genre mixes from clustering recent listens
A new cluster_mix_rule clusters a Listenbrainz user's listens from the last few months by MusicBrainz genre (with tracks played in the same session pulled together) and maintains one Subsonic playlist per cluster, filled with the cluster's most played tracks plus unheard library songs from the best matching library genres. - listenbrainz: fetch raw listens since a timestamp and bulk recording genres, handling rate limits - cluster: tag TF-IDF + co-listen smoothing, spherical k-means with k chosen by silhouette score - mix: match cluster profiles to library genres and pick songs, with a per-artist cap; reuse playlists across rebuilds by genre overlap - subsonic: getGenres, getSongsByGenre, rename/delete playlist, genre and MBID fields on tracks, API error detection - daemon, migration, POST/GET /api/playlist/mix and README docs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018opPJMJjLWr4RqdG6vuK6p
This commit is contained in:
13 files changed
+1728
-5
No files matched your search
@@ -63,3 +63,51 @@ For a yearly top songs playlist, run the following:
|
||||
INSERT INTO create_tracked_playlist (id, name_template, playlist_size, tracking_user, tracking_type)
|
||||
VALUES (gen_random_uuid(), '%Y - Top 100', 100, 'jellywx', 'this_year');
|
||||
```
|
||||
|
||||
### Genre mixes
|
||||
|
||||
A cluster mix rule groups the tracks you've listened to over the last few months by genre, and
|
||||
keeps one Subsonic playlist ("mix") per group, filled with songs from your library.
|
||||
|
||||
How it works:
|
||||
|
||||
1. Your listens for the period are fetched from Listenbrainz, along with the MusicBrainz genres of
|
||||
each recording, its release group and its artists.
|
||||
2. Tracks are clustered on their genres. Tracks you tend to play in the same listening session are
|
||||
pulled closer together, so untagged tracks and genre-hopping artists land with what you play
|
||||
them next to. The number of clusters is chosen automatically unless you set one.
|
||||
3. Each cluster's most characteristic genres are matched against your library's genres
|
||||
(`getGenres` / `getSongsByGenre`), case and punctuation insensitively, so a library tagged with
|
||||
MusicBrainz genres by Picard works best.
|
||||
4. Each mix is made of the cluster's most played tracks (`familiar_ratio` of the mix), plus songs
|
||||
from the matching genres that you haven't played in the period, picked at random weighted by
|
||||
how well their genres fit, with at most `playlist_size / 8` songs per artist.
|
||||
|
||||
Mixes are rebuilt every `refresh_hours`. On a rebuild, existing mix playlists are reused for the
|
||||
new cluster with the most similar genres (and renamed), new playlists are created for new
|
||||
clusters, and playlists for clusters that no longer appear are deleted.
|
||||
|
||||
Create a rule through the API:
|
||||
|
||||
```sh
|
||||
curl -X POST localhost:8000/api/playlist/mix -H 'Content-Type: application/json' \
|
||||
-d '{"tracking_user": "jellywx", "months": 3, "playlist_size": 50}'
|
||||
```
|
||||
|
||||
or with SQL:
|
||||
|
||||
```sql
|
||||
INSERT INTO cluster_mix_rule (id, tracking_user, months, playlist_size)
|
||||
VALUES (gen_random_uuid(), 'jellywx', 3, 50);
|
||||
```
|
||||
|
||||
| Column | Default | Meaning |
|
||||
|------------------|-----------------|--------------------------------------------------------------|
|
||||
| `months` | 3 | Months of listening history to cluster |
|
||||
| `cluster_count` | automatic | Number of mixes |
|
||||
| `playlist_size` | 50 | Songs per mix |
|
||||
| `familiar_ratio` | 0.3 | Share of each mix taken from recently played tracks |
|
||||
| `name_template` | `Mix: {label}` | Playlist name; `{label}` becomes the mix's top genres |
|
||||
| `refresh_hours` | 24 | How often to rebuild the mixes |
|
||||
|
||||
Set `last_run` to `NULL` to rebuild a rule's mixes on the next daemon tick.
|
||||
Reference in new issue
Block a user