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

@@ -19,6 +19,7 @@ import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.get
import io.ktor.server.routing.routing
import java.nio.file.Files
import java.time.Instant
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.CoroutineScope
@@ -45,6 +46,8 @@ import win.taptap.musicmanager.db.MediaRepository
import win.taptap.musicmanager.db.MoodRepository
import win.taptap.musicmanager.discovery.DiscoveryService
import win.taptap.musicmanager.discovery.YtDlpSearch
import win.taptap.musicmanager.download.DownloadService
import win.taptap.musicmanager.download.YtDlpDownloader
import win.taptap.musicmanager.radio.RadioService
import win.taptap.musicmanager.scanner.CoverArtService
import win.taptap.musicmanager.scanner.MediaScanner
@@ -71,11 +74,39 @@ fun main() {
library = library,
coverArtService = coverArtService,
)
val downloadService = if (config.downloadsEnabled) {
Files.createDirectories(config.downloadDir)
DownloadService(
users = users,
library = library,
downloader = YtDlpDownloader(config.ytDlpPath),
tempDir = config.downloadDir,
startScan = { scanner.start(applicationScope) },
isScanning = { scanner.status().scanning },
folderId = config.downloadFolderId,
)
} else {
null
}
if (MediaRepository.countSongs() == 0L) {
log.info("Song table is empty, starting initial library scan")
scanner.start(applicationScope)
}
// Accepted recommendations that are not in the library are fetched in
// the background and promoted after a scan.
downloadService?.let { service ->
applicationScope.launch(Dispatchers.IO) {
delay(TimeUnit.MINUTES.toMillis(1))
while (isActive) {
val worked = runCatching { service.processOne() }
.onFailure { log.warn("Download worker error", it) }
.getOrDefault(false)
delay(if (worked) 1_000 else 20_000)
}
}
}
// Moods refresh their YT recommendations in the background; the client
// can also force a pass from the mood screen.
applicationScope.launch(Dispatchers.IO) {
@@ -157,6 +188,7 @@ fun main() {
transcoder = transcoder,
radioService = radioService,
discoveryService = discoveryService,
downloadsEnabled = config.downloadsEnabled,
startScan = { scanner.start(applicationScope) },
scanStatus = { scanner.status() },
)