feat: rebuild AudioManager around downloadable moods
CI / chart (push) Successful in 3s
CI / test (push) Successful in 2m2s
CI / chart-push (push) Successful in 4s
CI / image (push) Successful in 3m20s

- V8 wipe migration and the shared song store keyed by YouTube video id
- media store, indexer, downloader, recommendation top-up and refcounted GC
- mood songs plus the recommendation lifecycle and mixed radio pools
- new search, song and recommendation API; remove library/longform/seed routes
- chart PVC/media env, docs, Nix, README and an end-to-end smoke test
This commit is contained in:
TapTap committed 2026-11-15 21:37:39 +00:00
1 parent 50d8b6c580
commit 824eb36dd2
59 files changed
+3838 -5276

No files matched your search

@@ -12,18 +12,21 @@ class RadioServiceTest {
private val service = RadioService()
@Test
fun `recently played songs are penalized`() {
fun `recently played and already heard songs are penalized`() {
val song = song("s-1")
val fresh = service.scoreCandidate(
song, emptySet(), emptyList(), emptyList(), null, affinity = 0.0, jitter = 0.0,
)
val recent = service.scoreCandidate(
song, emptySet(), emptyList(), emptyList(), null, affinity = 0.0,
recent = setOf("s-1"), jitter = 0.0,
)
assertEquals(0.0, fresh)
assertEquals(-6.0, recent)
assertEquals(
0.0,
service.scoreCandidate(song, affinity = 0.0, recent = false, jitter = 0.0),
)
assertEquals(
-6.0,
service.scoreCandidate(song, affinity = 0.0, recent = true, jitter = 0.0),
)
assertEquals(
-20.0,
service.scoreCandidate(song, affinity = 0.0, recent = false, jitter = 0.0, heard = true),
)
}
@Test
@@ -34,145 +37,103 @@ class RadioServiceTest {
}
@Test
fun `seeds and matching genres are boosted`() {
val seeded = service.scoreCandidate(
song("s-1", genres = listOf("Ambient")),
seedIds = setOf("s-1"),
seedGenres = listOf("Ambient"),
seedArtistIds = emptyList(),
query = null,
affinity = 0.0,
jitter = 0.0,
)
val plain = service.scoreCandidate(
song("s-2"),
seedIds = setOf("s-1"),
seedGenres = listOf("Ambient"),
seedArtistIds = emptyList(),
query = null,
affinity = 0.0,
jitter = 0.0,
fun `higher scores are picked first`() {
val scored = listOf(
song("low", artist = "A") to 1.0,
song("high", artist = "B") to 9.0,
)
assertEquals(11.5, seeded)
assertEquals(0.0, plain)
val picked = service.pickMixed(scored, emptyList(), limit = 2, collectionPercent = 100)
assertEquals("high", picked.first().id)
}
@Test
fun `picks keep artists and albums apart`() {
fun `picks keep artists and albums apart when possible`() {
val scored = listOf(
song("s1", artist = "A", albumId = "al1") to 0.0,
song("s2", artist = "B", albumId = "al2") to 0.0,
song("s3", artist = "C", albumId = "al3") to 0.0,
song("s4", artist = "D", albumId = "al4") to 0.0,
song("s5", artist = "A", albumId = "al5") to 0.0,
song("s6", artist = "B", albumId = "al6") to 0.0,
song("s1", artist = "A", album = "a1") to 0.0,
song("s2", artist = "B", album = "a2") to 0.0,
song("s3", artist = "C", album = "a3") to 0.0,
song("s4", artist = "D", album = "a4") to 0.0,
song("s5", artist = "A", album = "a5") to 0.0,
song("s6", artist = "B", album = "a6") to 0.0,
)
val picked = service.pickDiverse(scored, limit = 6)
val picked = service.pickMixed(
scored,
emptyList(),
limit = 6,
collectionPercent = 100,
artistSpacing = 2,
albumSpacing = 3,
)
assertEquals(6, picked.size)
picked.indices.forEach { index ->
val artists = picked.subList(index, minOf(index + 3, picked.size)).map { it.displayArtist }
val artists = picked.subList(index, minOf(index + 3, picked.size)).map { it.artist }
assertEquals(artists.size, artists.distinct().size, "artist spacing at $index")
val albums = picked.subList(index, minOf(index + 4, picked.size)).map { it.albumId }
assertEquals(albums.size, albums.distinct().size, "album spacing at $index")
}
}
@Test
fun `picks relax spacing when the pool is too small`() {
val scored = listOf(
song("s1", artist = "A", albumId = "al1") to 0.0,
song("s2", artist = "A", albumId = "al1") to 0.0,
)
val picked = service.pickDiverse(scored, limit = 2)
assertEquals(listOf("s1", "s2"), picked.map { it.id })
}
@Test
fun `higher scores are picked first`() {
val scored = listOf(
song("low", artist = "A", albumId = "al1") to 1.0,
song("high", artist = "B", albumId = "al2") to 9.0,
)
assertTrue(service.pickDiverse(scored, limit = 2).first().id == "high")
}
@Test
fun `mood mix draws from seeds and recommendations in proportion`() {
val seeds = (1..20).map { song("seed-$it", artist = "Seed $it") }
fun `mood mix draws from collection and recommendations in proportion`() {
val collection = (1..20).map { song("col-$it", artist = "Col $it") }
val recommendations = (1..20).map { song("rec-$it", artist = "Rec $it") }
val seedScored = seeds.mapIndexed { index, song -> song to (10.0 - index * 0.1) }
val collectionScored = collection.mapIndexed { index, song -> song to (10.0 - index * 0.1) }
val recommendationScored = recommendations.mapIndexed { index, song -> song to (9.0 - index * 0.1) }
val allSeeds = RadioService(Random(1)).pickMixed(
seedScored, recommendationScored, limit = 10, seedPercent = 100,
val allCollection = RadioService(Random(1)).pickMixed(
collectionScored, recommendationScored, limit = 10, collectionPercent = 100,
)
assertTrue(allSeeds.all { it.id.startsWith("seed-") })
assertTrue(allCollection.all { it.id.startsWith("col-") })
val allRecommendations = RadioService(Random(1)).pickMixed(
seedScored, recommendationScored, limit = 10, seedPercent = 0,
collectionScored, recommendationScored, limit = 10, collectionPercent = 0,
)
assertTrue(allRecommendations.all { it.id.startsWith("rec-") })
val mixed = RadioService(Random(7)).pickMixed(
seedScored, recommendationScored, limit = 20, seedPercent = 50,
collectionScored, recommendationScored, limit = 20, collectionPercent = 50,
)
assertEquals(20, mixed.size)
assertEquals(20, mixed.map { it.id }.distinct().size)
assertTrue(mixed.any { it.id.startsWith("seed-") })
assertTrue(mixed.any { it.id.startsWith("col-") })
assertTrue(mixed.any { it.id.startsWith("rec-") })
}
@Test
fun `mood mix falls back when one pool is empty`() {
val seeds = listOf(song("only-seed"))
val onlyCollection = listOf(song("only-collection"))
val picked = RadioService(Random(1)).pickMixed(
seedScored = seeds.map { it to 1.0 },
collectionScored = onlyCollection.map { it to 1.0 },
recommendationScored = emptyList(),
limit = 5,
seedPercent = 0,
collectionPercent = 0,
)
assertEquals(listOf("only-seed"), picked.map { it.id })
assertEquals(listOf("only-collection"), picked.map { it.id })
}
private fun song(
id: String,
artist: String = "Artist $id",
albumId: String = "album-$id",
genres: List<String> = emptyList(),
album: String? = "Album $id",
) = SongRecord(
id = id,
albumId = albumId,
albumName = "Album",
artistId = "ar-$artist",
artistName = artist,
displayArtist = artist,
videoId = "video-$id",
title = "Title $id",
trackNumber = 1,
discNumber = 1,
year = 2026,
artist = artist,
album = album,
duration = 180,
bitRate = 320,
size = 1_000,
suffix = "mp3",
contentType = "audio/mpeg",
coverArt = null,
folderId = 1,
relativePath = "$id.mp3",
created = "2026-01-01T00:00:00Z",
relativePath = "video-$id/$id.mp3",
fileMtime = 0,
thumbnail = null,
createdAt = "2026-01-01T00:00:00Z",
updatedAt = "2026-01-01T00:00:00Z",
starredAt = null,
rating = null,
playCount = 0,
lastPlayedAt = null,
artists = emptyList(),
genres = genres,
)
}