feat: add Deezer as the default download source
CI / chart (push) Successful in 3s
CI / test (push) Successful in 2m23s
CI / chart-push (push) Successful in 5s
CI / image (push) Successful in 3m50s

- V9 adds source/external_id to songs, moods, recommendations and jobs
- Deezer public catalog for search, related album covers and metadata
- streamrip downloader configured with DEEZER_ARL, 128/320 MP3
- per-mood source selector; switching clears and refills recommendations
- keep YouTube Music as a full second catalog and downloader
- media layout <source>-<externalId>, legacy YouTube folders still read
- Docker/streamrip install, chart ARL secret, docs and dual-source smoke test
This commit is contained in:
TapTap committed 2026-11-17 07:32:34 +00:00
1 parent 81a47f4cd2
commit 141698282d
43 files changed
+2072 -605

No files matched your search

@@ -19,12 +19,12 @@ data class DiscoveryOutcome(
)
/**
* Turns a mood's collection, genres and free text into YouTube candidates.
* Candidates are stored as hidden `new` rows; [win.taptap.musicmanager.discovery.TopUpService]
* promotes them into active download slots.
* Turns a mood's collection, genres and free text into catalog candidates.
* Candidates are stored as hidden `new` rows; [TopUpService] promotes them into
* active download slots.
*/
class DiscoveryService(
private val search: YtSearch,
private val catalogs: MusicCatalogs,
private val clock: () -> Instant = { Instant.now() },
) {
private val log = LoggerFactory.getLogger(DiscoveryService::class.java)
@@ -37,6 +37,7 @@ class DiscoveryService(
return DiscoveryOutcome(0, skipped = true)
}
val catalog = catalogs.forSource(mood.source)
val collection = MoodRepository.songRecords(mood.id)
val seedArtists = collection.map { it.artist }.filter { it.isNotBlank() }
val queries = buildQueries(mood, seedArtists)
@@ -46,11 +47,11 @@ class DiscoveryService(
}
// Queries are independent; running them together keeps a refresh within
// the client's request timeout even when yt-dlp is slow.
// the client's request timeout even when a catalog is slow.
val results = coroutineScope {
queries.map { query ->
async(Dispatchers.IO) {
runCatching { search.search(query, QUERY_LIMIT) }
runCatching { catalog.search(query, QUERY_LIMIT) }
}
}.awaitAll()
}
@@ -58,45 +59,47 @@ class DiscoveryService(
if (failures.size == queries.size) {
val message = failures.firstNotNullOfOrNull { it.exceptionOrNull()?.message }
?: "Search failed"
log.warn("YT discovery failed for mood {}: {}", mood.name, message)
log.warn("{} discovery failed for mood {}: {}", catalog.source, mood.name, message)
MoodRepository.markError(mood.id, message)
return DiscoveryOutcome(0, error = message)
}
val candidates = LinkedHashMap<String, YtCandidate>()
val candidates = LinkedHashMap<String, TrackCandidate>()
results.mapNotNull { it.getOrNull() }.flatten().forEach { candidate ->
if (isMusicLength(candidate.duration)) {
candidates.putIfAbsent(candidate.videoId, candidate)
candidates.putIfAbsent(candidate.externalId, candidate)
}
}
if (candidates.isEmpty()) {
val message = "YouTube returned no usable results"
val message = "${catalog.source} returned no usable results"
MoodRepository.markError(mood.id, message)
return DiscoveryOutcome(0, error = message)
}
val excluded = MoodRepository.videoIdsInMood(mood.id) + MoodRepository.decidedVideoIds(mood.id) +
val excluded = MoodRepository.externalIdsInMood(mood.id, mood.source) +
MoodRepository.decidedExternalIds(mood.id, mood.source) +
MoodRepository.allRecommendations(mood.id)
.filter { it.state != "new" }
.map { it.videoId }
.filter { it.source == mood.source && it.state != "new" }
.map { it.externalId }
.toSet()
val moodText = listOfNotNull(mood.query, mood.description, mood.name).joinToString(" ")
val upserts = candidates.values
.filterNot { it.videoId in excluded }
.filterNot { it.externalId in excluded }
.map { candidate ->
candidate to scoreCandidate(candidate, seedArtists, moodText)
}
.sortedWith(
compareByDescending<Pair<YtCandidate, Double>> { it.second }
compareByDescending<Pair<TrackCandidate, Double>> { it.second }
.thenBy { it.first.title },
)
.take(CANDIDATE_POOL)
.map { (candidate, _) ->
RecommendationUpsert(
videoId = candidate.videoId,
source = mood.source,
externalId = candidate.externalId,
title = candidate.title,
artist = candidate.artist,
album = candidate.album,
@@ -110,9 +113,15 @@ class DiscoveryService(
return DiscoveryOutcome(0)
}
val stored = MoodRepository.storeCandidates(mood.id, upserts, now.toString(), CANDIDATE_POOL)
val stored = MoodRepository.storeCandidates(
mood.id,
mood.source,
upserts,
now.toString(),
CANDIDATE_POOL,
)
MoodRepository.markDiscovered(mood.id)
log.info("YT discovery for mood {} stored {} candidates", mood.name, stored)
log.info("{} discovery for mood {} stored {} candidates", catalog.source, mood.name, stored)
return DiscoveryOutcome(stored = stored)
}
@@ -146,7 +155,7 @@ internal fun buildQueries(mood: MoodRecord, seedArtists: List<String>): List<Str
}
internal fun scoreCandidate(
candidate: YtCandidate,
candidate: TrackCandidate,
seedArtists: List<String>,
moodText: String,
): Double {