feat: download accepted recommendations and track longform progress
Accepted recommendations without a library match now enter a download queue. A worker downloads the MP3 with yt-dlp into "<music>/AudioManager Imports", runs a scan, matches the new song, links it to the recommendation and adds it as a seed. Jobs retry three times and expose queued/downloading/done/failed state (plus the error) on the recommendation DTO, so clients can show progress and retry. Downloads can be disabled and the target folder chosen. Long-form gets resume points: GET/PUT /longform/progress, scoped to longform folders and to the owner, with automatic completion detection. Longform stays excluded from moods and radio. The chart mounts the music hostPath writable for imports and passes the new DOWNLOAD_* settings; version 0.2.3.
This commit is contained in:
1 parent
51d1b20bf6
commit
a5af1ee83f
18 files changed
+996
-9
No files matched your search
@@ -5,6 +5,7 @@ import io.ktor.client.request.delete
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.header
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.put
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.bodyAsBytes
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
@@ -50,6 +51,7 @@ import win.taptap.musicmanager.db.ArtistsTable
|
||||
import win.taptap.musicmanager.db.ConfigRepository
|
||||
import win.taptap.musicmanager.db.DatabaseFactory
|
||||
import win.taptap.musicmanager.db.DatabaseHandle
|
||||
import win.taptap.musicmanager.db.DownloadRepository
|
||||
import win.taptap.musicmanager.db.SongArtistsTable
|
||||
import win.taptap.musicmanager.db.SongGenresTable
|
||||
import win.taptap.musicmanager.db.SongsTable
|
||||
@@ -304,12 +306,20 @@ class ApiRoutesTest {
|
||||
assertEquals("accepted", acceptedBody["recommendation"]!!.jsonObject.string("state"))
|
||||
assertEquals(2, acceptedBody["detail"]!!.jsonObject["mood"]!!.jsonObject.int("seedCount"))
|
||||
|
||||
// Unknown tracks are accepted for the future downloader.
|
||||
// Unknown tracks are accepted and queued for automatic download.
|
||||
val acceptedNew = client.post("/api/v1/moods/$moodId/recommendations/v-new/accept") {
|
||||
bearer(token)
|
||||
}
|
||||
val acceptedNewBody = parse(acceptedNew.bodyAsText())
|
||||
assertFalse(acceptedNewBody["seedAdded"]!!.jsonPrimitive.content.toBoolean())
|
||||
assertEquals(
|
||||
"queued",
|
||||
DownloadRepository.forRecommendation("alice", moodId, "v-new")?.state,
|
||||
)
|
||||
assertEquals(
|
||||
"queued",
|
||||
acceptedNewBody["recommendation"]!!.jsonObject["download"]!!.jsonObject.string("state"),
|
||||
)
|
||||
assertEquals(
|
||||
"accepted",
|
||||
acceptedNewBody["recommendation"]!!.jsonObject.string("state"),
|
||||
@@ -344,6 +354,47 @@ class ApiRoutesTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `longform progress is saved resumed and owner scoped`() {
|
||||
seededContext().use { seed ->
|
||||
testApplication {
|
||||
setupApp(seed)
|
||||
val alice = client.token("alice", "alice-pw")
|
||||
|
||||
val saved = client.put("/api/v1/longform/progress/${seed.longformSong}") {
|
||||
bearer(alice)
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody("""{"positionSeconds":42,"durationSeconds":120}""")
|
||||
}
|
||||
assertEquals(HttpStatusCode.NoContent, saved.status)
|
||||
|
||||
val list = parseBody(
|
||||
client.get("/api/v1/longform/progress") { bearer(alice) }.bodyAsText(),
|
||||
)
|
||||
val item = list["items"]!!.jsonArray.single().jsonObject
|
||||
assertEquals(seed.longformSong, item["song"]!!.jsonObject.string("id"))
|
||||
assertEquals(42, item.int("positionSeconds"))
|
||||
assertFalse(item["completed"]!!.jsonPrimitive.content.toBoolean())
|
||||
|
||||
// Music tracks are not longform.
|
||||
val music = client.put("/api/v1/longform/progress/${seed.aliceRock}") {
|
||||
bearer(alice)
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody("""{"positionSeconds":10}""")
|
||||
}
|
||||
assertEquals(HttpStatusCode.NotFound, music.status)
|
||||
|
||||
// Progress is private to the owner.
|
||||
val bob = client.token("bob", "bob-pw")
|
||||
val bobList = parseBody(
|
||||
client.get("/api/v1/longform/progress") { bearer(bob) }.bodyAsText(),
|
||||
)
|
||||
assertTrue(bobList["items"]!!.jsonArray.isEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a session is scoped to its owner`() {
|
||||
seededContext().use { seed ->
|
||||
|
||||
Reference in new issue
Block a user