feat: rebuild AudioManager around downloadable moods
CI / chart (push) Successful in 3s
CI / test (push) Successful in 2m2s
CI / chart-push (push) Successful in 4s
CI / image (push) Successful in 3m20s

- V8 wipe migration and the shared song store keyed by YouTube video id
- media store, indexer, downloader, recommendation top-up and refcounted GC
- mood songs plus the recommendation lifecycle and mixed radio pools
- new search, song and recommendation API; remove library/longform/seed routes
- chart PVC/media env, docs, Nix, README and an end-to-end smoke test
This commit is contained in:
TapTap committed 2026-11-15 21:37:39 +00:00
1 parent 50d8b6c580
commit 824eb36dd2
59 files changed
+3838 -5276

No files matched your search

@@ -2,7 +2,8 @@ package win.taptap.musicmanager.api
import kotlinx.serialization.Serializable
import win.taptap.musicmanager.db.MoodRecord
import win.taptap.musicmanager.db.MoodSeedRecord
import win.taptap.musicmanager.db.MoodSongRecord
import win.taptap.musicmanager.db.RecommendationRecord
import win.taptap.musicmanager.db.SongRecord
@Serializable
@@ -23,8 +24,6 @@ data class LoginRequest(
data class UserDto(
val name: String,
val admin: Boolean,
val musicFolders: List<Int>,
val longformFolders: List<Int>,
)
@Serializable
@@ -48,49 +47,40 @@ data class DeviceDto(
@Serializable
data class SongDto(
val id: String,
val videoId: String,
val title: String,
val artist: String,
val album: String,
val albumId: String,
val trackNumber: Int? = null,
val discNumber: Int = 1,
val year: Int? = null,
val album: String? = null,
val duration: Int,
val bitRate: Int,
val size: Long,
val suffix: String,
val genres: List<String> = emptyList(),
val folderId: Int,
val relativePath: String,
val updatedAt: String,
val thumbnail: String? = null,
)
fun SongRecord.toDto(): SongDto = SongDto(
id = id,
videoId = videoId,
title = title,
artist = displayArtist,
album = albumName,
albumId = albumId,
trackNumber = trackNumber,
discNumber = discNumber,
year = year,
artist = artist,
album = album,
duration = duration,
bitRate = bitRate,
size = size,
suffix = suffix,
genres = genres,
folderId = folderId,
relativePath = relativePath,
updatedAt = updatedAt,
thumbnail = thumbnail,
)
@Serializable
data class SeedDto(
data class MoodSongDto(
val song: SongDto,
val origin: String,
val addedAt: String,
)
fun MoodSongRecord.toDto(song: SongRecord): MoodSongDto =
MoodSongDto(song = song.toDto(), origin = origin, addedAt = addedAt)
@Serializable
data class MoodDto(
val id: String,
@@ -98,17 +88,18 @@ data class MoodDto(
val description: String? = null,
val query: String? = null,
val genres: List<String> = emptyList(),
val targetSize: Int,
val seedPercent: Int,
val collectionPercent: Int,
val recommendationPercent: Int,
val recommendationCount: Int,
val refreshHours: Int,
val ytEnabled: Boolean,
val lastDiscoveryAt: String? = null,
val createdAt: String,
val changedAt: String,
val lastError: String? = null,
val seedCount: Int,
val newRecommendations: Int,
val songCount: Int,
val recommendationReady: Int,
val recommendationDownloading: Int,
val recommendationFailed: Int,
)
fun MoodRecord.toDto(): MoodDto = MoodDto(
@@ -117,45 +108,93 @@ fun MoodRecord.toDto(): MoodDto = MoodDto(
description = description,
query = query,
genres = genres,
targetSize = targetSize,
seedPercent = seedPercent,
recommendationPercent = 100 - seedPercent,
collectionPercent = collectionPercent,
recommendationPercent = 100 - collectionPercent,
recommendationCount = recommendationCount,
refreshHours = refreshHours,
ytEnabled = ytEnabled,
lastDiscoveryAt = lastDiscoveryAt,
createdAt = createdAt,
changedAt = changedAt,
lastError = lastError,
seedCount = seedCount,
newRecommendations = newRecommendations,
songCount = songCount,
recommendationReady = recommendationReady,
recommendationDownloading = recommendationDownloading,
recommendationFailed = recommendationFailed,
)
@Serializable
data class MoodDetailDto(
val mood: MoodDto,
val seeds: List<SeedDto>,
val songs: List<MoodSongDto> = emptyList(),
val recommendations: List<RecommendationDto> = emptyList(),
)
@Serializable
data class RecommendationDecisionDto(
val detail: MoodDetailDto,
val recommendation: RecommendationDto,
val seedAdded: Boolean = false,
data class RecommendationDto(
val videoId: String,
val title: String,
val artist: String,
val album: String? = null,
val duration: Int? = null,
val thumbnail: String? = null,
val state: String,
val song: SongDto? = null,
val download: DownloadDto? = null,
val error: String? = null,
val firstSeen: String,
val lastSeen: String,
)
fun RecommendationRecord.toDto(
song: SongRecord? = null,
download: DownloadDto? = null,
): RecommendationDto = RecommendationDto(
videoId = videoId,
title = title,
artist = artist,
album = album,
duration = duration,
thumbnail = thumbnail,
state = state,
song = song?.toDto(),
download = download,
error = error,
firstSeen = firstSeen,
lastSeen = lastSeen,
)
@Serializable
data class DownloadDto(
val state: String,
val attempts: Int,
val error: String? = null,
val updatedAt: String,
)
@Serializable
data class SearchResultDto(
val videoId: String,
val title: String,
val artist: String,
val album: String? = null,
val duration: Int? = null,
val thumbnail: String? = null,
val songId: String? = null,
val downloaded: Boolean = false,
)
@Serializable
data class SearchResponse(val results: List<SearchResultDto> = emptyList())
@Serializable
data class CreateMoodRequest(
val name: String,
val description: String? = null,
val query: String? = null,
val genres: List<String> = emptyList(),
val targetSize: Int = 30,
val collectionPercent: Int = 50,
val recommendationCount: Int = 10,
val refreshHours: Int = 24,
val ytEnabled: Boolean = true,
val seedSongIds: List<String> = emptyList(),
/** Share of each batch that comes from the seed songs; the rest is recommended. */
val seedPercent: Int = 50,
)
@Serializable
@@ -166,14 +205,36 @@ data class UpdateMoodRequest(
val query: String? = null,
val clearQuery: Boolean = false,
val genres: List<String>? = null,
val targetSize: Int? = null,
val collectionPercent: Int? = null,
val recommendationCount: Int? = null,
val refreshHours: Int? = null,
val ytEnabled: Boolean? = null,
val seedPercent: Int? = null,
)
/**
* Adding music accepts one of:
* - `songId`: an already downloaded song, attached instantly;
* - `videoId`: a YouTube id from search, downloaded if necessary;
* - `url`: a pasted watch URL resolved by yt-dlp.
*/
@Serializable
data class AddSongRequest(
val songId: String? = null,
val videoId: String? = null,
val url: String? = null,
)
@Serializable
data class AddSeedRequest(val songId: String, val origin: String = "manual")
data class AddSongResponse(
val detail: MoodDetailDto,
val added: Boolean,
val downloading: Boolean = false,
)
@Serializable
data class RecommendationDecisionDto(
val detail: MoodDetailDto,
val recommendation: RecommendationDto,
)
@Serializable
data class AddToMoodRequest(val songId: String, val moodId: String? = null)
@@ -185,16 +246,7 @@ data class AddToMoodResponse(
)
@Serializable
data class LibraryPage(
val songs: List<SongDto>,
val deletedSongIds: List<String> = emptyList(),
val revision: String,
val nextCursor: String? = null,
val nextSince: String? = null,
)
@Serializable
data class SearchResponse(val songs: List<SongDto>)
data class TracksResponse(val songs: List<SongDto>)
@Serializable
data class StartSessionRequest(val limit: Int? = null)
@@ -234,49 +286,3 @@ data class ScanStatusDto(
val count: Long,
val error: String? = null,
)
@Serializable
data class DownloadDto(
val state: String,
val attempts: Int,
val error: String? = null,
val updatedAt: String,
)
@Serializable
data class RecommendationDto(
val videoId: String,
val title: String,
val artist: String,
val album: String? = null,
val duration: Int? = null,
val thumbnail: String? = null,
val state: String,
val matchedSong: SongDto? = null,
val timesAdded: Int,
val firstSeen: String,
val lastSeen: String,
val download: DownloadDto? = null,
)
@Serializable
data class LongformProgressDto(
val song: SongDto,
val positionSeconds: Int,
val durationSeconds: Int,
val completed: Boolean,
val updatedAt: String,
)
@Serializable
data class LongformProgressResponse(val items: List<LongformProgressDto> = emptyList())
@Serializable
data class SaveLongformProgressRequest(
val positionSeconds: Int,
val durationSeconds: Int? = null,
val completed: Boolean = false,
)
fun seedDto(seed: MoodSeedRecord, song: SongRecord): SeedDto =
SeedDto(song = song.toDto(), origin = seed.origin, addedAt = seed.addedAt)