feat: download accepted recommendations and track longform progress
CI / chart (push) Successful in 4s
CI / chart-push (push) Successful in 4s
CI / test (push) Successful in 2m5s
CI / image (push) Successful in 3m14s

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:
TapTap committed 2026-11-15 13:26:22 +00:00
1 parent 51d1b20bf6
commit a5af1ee83f
18 files changed
+996 -9

No files matched your search

@@ -15,6 +15,7 @@ import win.taptap.musicmanager.api.AddToMoodResponse
import win.taptap.musicmanager.api.CreateMoodRequest
import win.taptap.musicmanager.api.MoodDetailDto
import win.taptap.musicmanager.api.MoodDto
import win.taptap.musicmanager.api.DownloadDto
import win.taptap.musicmanager.api.RecommendationDecisionDto
import win.taptap.musicmanager.api.RecommendationDto
import win.taptap.musicmanager.api.SearchResponse
@@ -24,6 +25,7 @@ import win.taptap.musicmanager.api.toDto
import win.taptap.musicmanager.config.LibraryConfig
import win.taptap.musicmanager.config.UserAccount
import win.taptap.musicmanager.config.UsersConfig
import win.taptap.musicmanager.db.DownloadRepository
import win.taptap.musicmanager.db.LibraryRepository
import win.taptap.musicmanager.db.MoodRecord
import win.taptap.musicmanager.db.MoodRepository
@@ -38,6 +40,7 @@ fun Route.moodRoutes(
library: LibraryConfig,
radioService: RadioService,
discoveryService: DiscoveryService,
downloadsEnabled: Boolean,
) {
get("/moods") {
val user = call.requireApiUser(users)
@@ -184,6 +187,15 @@ fun Route.moodRoutes(
val alreadyAccepted = recommendation.state == "accepted"
MoodRepository.setRecommendationState(mood.id, videoId, "accepted")
if (!alreadyAccepted) MoodRepository.incrementRecommendationAdds(mood.id, videoId)
if (matched == null && downloadsEnabled) {
DownloadRepository.enqueue(
userName = user.name,
moodId = mood.id,
videoId = recommendation.videoId,
title = recommendation.title,
artist = recommendation.artist,
)
}
call.respond(decision(mood.id, videoId, user, library, seedAdded))
}
@@ -234,6 +246,7 @@ private fun recommendations(
val matchedSongs = LibraryRepository
.songsByIds(matchedIds, user.visibleFolderIds(library), user.name)
.associateBy { it.id }
val downloads = DownloadRepository.forMood(user.name, mood.id)
return RecommendationsResponse(
recommendations = records.map { record ->
@@ -249,6 +262,14 @@ private fun recommendations(
timesAdded = record.timesAdded,
firstSeen = record.firstSeen,
lastSeen = record.lastSeen,
download = downloads[record.videoId]?.let { job ->
DownloadDto(
state = job.state,
attempts = job.attempts,
error = job.error,
updatedAt = job.updatedAt,
)
},
)
},
)