feat: recommend from Deezer and YouTube Music radios
CI / chart (push) Successful in 2s
CI / test (push) Successful in 1m57s
CI / chart-push (push) Successful in 5s
CI / image (push) Successful in 3m39s

- Deezer: /artist/{id}/radio for collection artists, affinity 2.0
- YouTube Music: RDAMVM watch playlist via yt-dlp, affinity 2.0
- seed radios from the 2 newest songs of the mood's own catalog
- dedupe candidates by recording, not only by external id
- clean raw YouTube titles and Topic suffixes when indexing
- tests, smoke marker for the RDAMVM path, docs
This commit is contained in:
TapTap committed 2026-11-17 15:22:05 +00:00
1 parent 62bcefad20
commit 26c41cc7d9
12 files changed
+296 -44

No files matched your search

@@ -36,6 +36,13 @@ class DeezerDiscoverTest {
"artist":{"name":"Daft Punk"},
"album":{"title":"Random Access Memories"}}]}""",
)
"/artist/27/radio" ->
ok(
"""{"data":[
{"id":5,"title":"Kids","duration":303,"readable":true,
"artist":{"name":"MGMT"},
"album":{"title":"Oracular Spectacular"}}]}""",
)
"/artist/27/related" ->
ok("""{"data":[{"id":99,"name":"Daft Punk Tribute"}]}""")
"/artist/99/top" ->
@@ -58,8 +65,11 @@ class DeezerDiscoverTest {
val found = catalog(server).discover(seeds(), limit = 50).associateBy { it.externalId }
// The 15-minute track is not music-length and never reaches the pool.
assertEquals(setOf("1", "3", "4"), found.keys)
assertEquals(setOf("1", "3", "4", "5"), found.keys)
assertEquals(0.5, found.getValue("1").affinity)
// Deezer's own radio is the strongest affinity signal we can get.
assertEquals(2.0, found.getValue("5").affinity)
assertEquals("MGMT", found.getValue("5").artist)
assertEquals(1.5, found.getValue("3").affinity)
assertEquals(1.0, found.getValue("4").affinity)
// `/album/{id}/tracks` has no album object; the search result fills it in.
@@ -268,6 +268,34 @@ class DiscoveryServiceTest {
assertEquals(1.0, sameAlbum - unrelated)
}
@Test
fun `merge keeps one copy of a recording and prefers the stronger affinity`() {
val album = TrackCandidate(
source = MusicSource.DEEZER,
externalId = "album-copy",
title = "Get Lucky (Radio Edit)",
artist = "Daft Punk",
duration = 248,
)
val radio = album.copy(externalId = "radio-copy", affinity = 2.0)
val cover = TrackCandidate(
source = MusicSource.DEEZER,
externalId = "cover",
title = "Get Lucky",
artist = "Daft Punk Tribute",
duration = 240,
)
val merged = mergeCandidates(listOf(album, cover, radio))
assertEquals(setOf("radio-copy", "cover"), merged.keys)
assertEquals(2.0, merged.getValue("radio-copy").affinity)
assertEquals(
recordingKey("Daft Punk", "Get Lucky"),
recordingKey("Daft Punk", "Get Lucky (Radio Edit)"),
)
}
@Test
fun `ranking spreads picks across artists instead of repeating one`() {
val lead = (1..12).map {
@@ -348,6 +376,25 @@ class DiscoveryServiceTest {
)
}
@Test
fun `radio seeds use the newest song per artist of the same catalog`() {
val collection = listOf(
song("Alpha", externalId = "yt-1", source = MusicSource.YOUTUBE),
song("Beta", externalId = "yt-2", source = MusicSource.YOUTUBE),
song("Alpha", externalId = "yt-3", source = MusicSource.YOUTUBE),
song("Gamma", externalId = "dz-1", source = MusicSource.DEEZER),
)
assertEquals(
listOf("yt-3", "yt-2"),
radioSeedIds(collection, MusicSource.YOUTUBE, limit = 2),
)
assertEquals(
listOf("dz-1"),
radioSeedIds(collection, MusicSource.DEEZER, limit = 2),
)
}
@Test
fun `albums are collected once per title and artist`() {
val collection = listOf(
@@ -366,10 +413,15 @@ class DiscoveryServiceTest {
)
}
private fun song(artist: String, album: String? = "Album") = SongRecord(
id = "sg-$artist-$album",
source = MusicSource.DEEZER,
externalId = "1",
private fun song(
artist: String,
album: String? = "Album",
source: String = MusicSource.DEEZER,
externalId: String = "1",
) = SongRecord(
id = "sg-$artist-$album-$source-$externalId",
source = source,
externalId = externalId,
title = "Title",
artist = artist,
album = album,
@@ -43,6 +43,24 @@ class Mp3TagExtractorTest {
assertEquals("audio/mpeg", song.contentType)
}
@Test
fun `cleans the raw YouTube title prefix and upload noise`() {
TestAudio.assumeFfmpeg()
val file = tempDir.resolve("video-id/rick.mp3")
TestAudio.createMp3(
file,
metadata = mapOf(
"title" to "Rick Astley - Never Gonna Give You Up (Official Video) (4K Remaster)",
"artist" to "Rick Astley - Topic",
),
)
val song = assertNotNull(Mp3TagExtractor().extract(file))
assertEquals("Never Gonna Give You Up", song.title)
assertEquals("Rick Astley", song.artist)
}
@Test
fun `falls back to the file name and a generic artist`() {
TestAudio.assumeFfmpeg()