feat: mix mood radio by seed percentage and embed download artwork
CI / chart (push) Successful in 3s
CI / chart-push (push) Successful in 5s
CI / test (push) Successful in 1m50s
CI / image (push) Successful in 3m16s

Moods now store a seedPercent (0-100, default 50). RadioService rolls that
share independently for every queued slot: heads picks from the seed songs,
tails from the generated recommendation pool. When one pool is empty the other
fills the batch, so a mood never stalls. The DTO exposes both seedPercent and
the derived recommendationPercent, and create/patch accept seedPercent.

Automatic YT downloads now embed the video thumbnail as MP3 cover art so the
scanner publishes a cover for newly imported tracks.

V7 adds moods.seed_percent.
This commit is contained in:
TapTap committed 2026-11-15 17:07:04 +00:00
1 parent dd7bbde84d
commit c75f2971b4
11 files changed
+146 -6

No files matched your search

@@ -4,6 +4,7 @@ import io.ktor.client.HttpClient
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.patch
import io.ktor.client.request.post
import io.ktor.client.request.put
import io.ktor.client.request.setBody
@@ -153,6 +154,17 @@ class ApiRoutesTest {
val moodId = mood["mood"]!!.jsonObject.string("id")
assertEquals(1, mood["mood"]!!.jsonObject.int("seedCount"))
assertTrue(mood["seeds"]!!.jsonArray.isNotEmpty())
assertEquals(50, mood["mood"]!!.jsonObject.int("seedPercent"))
assertEquals(50, mood["mood"]!!.jsonObject.int("recommendationPercent"))
val mixed = client.patch("/api/v1/moods/$moodId") {
bearer(token)
contentType(ContentType.Application.Json)
setBody("""{"seedPercent":70}""")
}
val mixedMood = parse(mixed.bodyAsText())["mood"]!!.jsonObject
assertEquals(70, mixedMood.int("seedPercent"))
assertEquals(30, mixedMood.int("recommendationPercent"))
// Long-form can never be a mood seed.
val withLongform = client.post("/api/v1/moods") {
@@ -101,6 +101,7 @@ class DiscoveryServiceTest {
query = query,
genres = genres,
targetSize = 30,
seedPercent = 50,
refreshHours = 24,
ytEnabled = true,
lastDiscoveryAt = null,
@@ -1,5 +1,6 @@
package win.taptap.musicmanager.radio
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@@ -101,6 +102,46 @@ class RadioServiceTest {
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") }
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 recommendationScored = recommendations.mapIndexed { index, song -> song to (9.0 - index * 0.1) }
val allSeeds = RadioService(Random(1)).pickMixed(
seedScored, recommendationScored, limit = 10, seedPercent = 100,
)
assertTrue(allSeeds.all { it.id.startsWith("seed-") })
val allRecommendations = RadioService(Random(1)).pickMixed(
seedScored, recommendationScored, limit = 10, seedPercent = 0,
)
assertTrue(allRecommendations.all { it.id.startsWith("rec-") })
val mixed = RadioService(Random(7)).pickMixed(
seedScored, recommendationScored, limit = 20, seedPercent = 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("rec-") })
}
@Test
fun `mood mix falls back when one pool is empty`() {
val seeds = listOf(song("only-seed"))
val picked = RadioService(Random(1)).pickMixed(
seedScored = seeds.map { it to 1.0 },
recommendationScored = emptyList(),
limit = 5,
seedPercent = 0,
)
assertEquals(listOf("only-seed"), picked.map { it.id })
}
private fun song(
id: String,
artist: String = "Artist $id",