feat(slint/discover): DailyQ/WeeklyQ primary track_to_analysed path
Bring the Slint mix generation to Tauri parity: build a track_to_analysed
payload from up to 9 spread-sampled seeds (pick_spread -> get_track ->
{track_id,artist_id,genre_id,label_id}, drop artist_id==0) for the PRIMARY
/dynamic/suggest algorithm, limit = max(1, 50 - analysed), and fall back to
the empty-analysis call when the primary returns nothing. The listened-seed
build is factored into mix_listened_seed_ids (recents + favorites, ~120,
Qobuz-only) as a seam the reco-store swap (b3) replaces. Logs seed/analysed/
result counts so an empty mix is diagnosable.
cc
This commit is contained in:
1 file changed
+116
-15
+116
-15
@@ -12,11 +12,12 @@
|
|||||||
//! playlist play-stats ranking — is approximated; the same surfaces
|
//! playlist play-stats ranking — is approximated; the same surfaces
|
||||||
//! and playback result, sourced from available backend.)
|
//! and playback result, sourced from available backend.)
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::sync::{LazyLock, Mutex};
|
use std::sync::{LazyLock, Mutex};
|
||||||
|
|
||||||
use qbz_app::shell::AppRuntime;
|
use qbz_app::shell::AppRuntime;
|
||||||
use qbz_core::FrontendAdapter;
|
use qbz_core::FrontendAdapter;
|
||||||
use qbz_models::Track;
|
use qbz_models::{Track, TrackToAnalyse};
|
||||||
use slint::{ComponentHandle, ModelRc, VecModel};
|
use slint::{ComponentHandle, ModelRc, VecModel};
|
||||||
|
|
||||||
use crate::artwork::{ArtworkJob, ArtworkTarget};
|
use crate::artwork::{ArtworkJob, ArtworkTarget};
|
||||||
@@ -36,31 +37,131 @@ pub fn mix_meta(kind: &str) -> (&'static str, &'static str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Even-spread sample of up to `n` ids across `ids` (Tauri's pickSpread):
|
||||||
|
/// stride through the list so the analysis seeds are not all clustered.
|
||||||
|
fn pick_spread(ids: &[u64], n: usize) -> Vec<u64> {
|
||||||
|
if ids.len() <= n {
|
||||||
|
return ids.to_vec();
|
||||||
|
}
|
||||||
|
(0..n).map(|i| ids[i * ids.len() / n]).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The DailyQ/WeeklyQ listened-track seed: recent QOBUZ plays + Qobuz
|
||||||
|
/// favorites, deduped, capped at 120 (mirrors Tauri's continueListening +
|
||||||
|
/// favorites merge). Local/Plex/ephemeral recents carry non-Qobuz ids and are
|
||||||
|
/// excluded; `qobuz_download` offline copies keep the real Qobuz id. A
|
||||||
|
/// recents-only seed is frequently empty for local-heavy users, so favorites
|
||||||
|
/// guarantee a non-empty seed.
|
||||||
|
///
|
||||||
|
/// NOTE (Slice b3): this body will be swapped to the shared reco-store
|
||||||
|
/// home-seeds; the call site and the rest of the mix path stay unchanged.
|
||||||
|
async fn mix_listened_seed_ids<A>(runtime: &AppRuntime<A>) -> Vec<u64>
|
||||||
|
where
|
||||||
|
A: FrontendAdapter + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
let mut seeds: Vec<u64> = crate::recently::load()
|
||||||
|
.into_iter()
|
||||||
|
.filter(|t| !matches!(t.source.as_str(), "local" | "plex" | "ephemeral"))
|
||||||
|
.filter_map(|t| t.id.parse::<u64>().ok())
|
||||||
|
.collect();
|
||||||
|
let mut seen: HashSet<u64> = seeds.iter().copied().collect();
|
||||||
|
for fav in favorite_tracks(runtime).await {
|
||||||
|
if seen.insert(fav.id) {
|
||||||
|
seeds.push(fav.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seeds.truncate(120);
|
||||||
|
seeds
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resolve up to 9 spread seeds into the `track_to_analysed` payload (the
|
||||||
|
/// PRIMARY DailyQ/WeeklyQ path, Tauri buildSeeds): `get_track` each, extract
|
||||||
|
/// `{track_id, artist_id, genre_id, label_id}` (artist = performer, else
|
||||||
|
/// composer; missing ids default to 0), drop any with `artist_id == 0`.
|
||||||
|
async fn build_tracks_to_analyse<A>(runtime: &AppRuntime<A>, seeds: &[u64]) -> Vec<TrackToAnalyse>
|
||||||
|
where
|
||||||
|
A: FrontendAdapter + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
let mut analysed = Vec::new();
|
||||||
|
for id in pick_spread(seeds, 9) {
|
||||||
|
let Ok(track) = runtime.core().get_track(id).await else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let artist_id = track
|
||||||
|
.performer
|
||||||
|
.as_ref()
|
||||||
|
.map(|a| a.id)
|
||||||
|
.or_else(|| track.composer.as_ref().map(|a| a.id))
|
||||||
|
.unwrap_or(0);
|
||||||
|
if artist_id == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
analysed.push(TrackToAnalyse {
|
||||||
|
track_id: track.id,
|
||||||
|
artist_id,
|
||||||
|
genre_id: track
|
||||||
|
.album
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|a| a.genre.as_ref())
|
||||||
|
.map(|g| g.id)
|
||||||
|
.unwrap_or(0),
|
||||||
|
label_id: track
|
||||||
|
.album
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|a| a.label.as_ref())
|
||||||
|
.map(|l| l.id)
|
||||||
|
.unwrap_or(0),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
analysed
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn load_mix<A>(runtime: &AppRuntime<A>, kind: &str) -> Vec<Track>
|
pub async fn load_mix<A>(runtime: &AppRuntime<A>, kind: &str) -> Vec<Track>
|
||||||
where
|
where
|
||||||
A: FrontendAdapter + Send + Sync + 'static,
|
A: FrontendAdapter + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
match kind {
|
match kind {
|
||||||
"daily" | "weekly" => {
|
"daily" | "weekly" => {
|
||||||
// Seed /dynamic/suggest with QOBUZ track ids ONLY. Recently-played
|
// Tauri buildSeeds parity: seed listened_tracks_ids from recent plays
|
||||||
// now includes local/Plex tracks whose ids are NOT in the Qobuz
|
// + favorites (~120), build a track_to_analysed payload from ~9 spread
|
||||||
// catalog (e.g. numeric Plex rating keys that pass the u64 parse);
|
// seeds for the PRIMARY algorithm, and fall back to the empty-analysis
|
||||||
// sending those made the mix request fail. Empty `source` = legacy
|
// call when the primary returns nothing. DailyQ vs WeeklyQ differ only
|
||||||
// pre-source entries (treated as Qobuz). Local/Plex are excluded.
|
// by cache bucket (see a3), not by the request.
|
||||||
let seeds: Vec<u64> = crate::recently::load()
|
let seeds = mix_listened_seed_ids(runtime).await;
|
||||||
.into_iter()
|
|
||||||
.filter(|t| t.source.is_empty() || t.source == "qobuz")
|
|
||||||
.filter_map(|t| t.id.parse::<u64>().ok())
|
|
||||||
.take(50)
|
|
||||||
.collect();
|
|
||||||
if seeds.is_empty() {
|
if seeds.is_empty() {
|
||||||
|
log::warn!(
|
||||||
|
"[qbz-slint] mix '{kind}': no Qobuz seed tracks (recents + favorites empty) — empty mix"
|
||||||
|
);
|
||||||
Vec::new()
|
Vec::new()
|
||||||
} else {
|
} else {
|
||||||
runtime
|
let analysed = build_tracks_to_analyse(runtime, &seeds).await;
|
||||||
|
let limit = (50usize.saturating_sub(analysed.len())).max(1) as u32;
|
||||||
|
let tracks = match runtime
|
||||||
.core()
|
.core()
|
||||||
.get_dynamic_suggest(&seeds, 50)
|
.get_dynamic_suggest_full(&seeds, &analysed, limit)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default()
|
{
|
||||||
|
Ok(tracks) if !tracks.is_empty() => tracks,
|
||||||
|
Ok(_) => {
|
||||||
|
// FALLBACK (Tauri): retry with empty analysis + limit 50.
|
||||||
|
runtime
|
||||||
|
.core()
|
||||||
|
.get_dynamic_suggest(&seeds, 50)
|
||||||
|
.await
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("[qbz-slint] mix '{kind}': dynamic/suggest failed: {e}");
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
log::info!(
|
||||||
|
"[qbz-slint] mix '{kind}': {} seeds, {} analysed -> {} tracks",
|
||||||
|
seeds.len(),
|
||||||
|
analysed.len(),
|
||||||
|
tracks.len()
|
||||||
|
);
|
||||||
|
tracks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"fav" => {
|
"fav" => {
|
||||||
|
|||||||
Reference in new issue
Block a user