feat(slint): add-to-playlist duplicate modal + playlist importer port
Add-to-playlist (Slices 0-3): - qbz-core: check_playlist_duplicates + pure compute_playlist_duplicates (reuses qbz_models::PlaylistDuplicateResult) + unit tests. - PlaylistDuplicateConfirmModal (Add all / Add new only / Cancel); the duplicate check runs on the Qobuz->Qobuz picker branch only (local/Plex add directly, mirroring Tauri); the track-id Vec lives Rust-side in a stash, never in Slint. - Inline create-and-add in the picker (online create_playlist, offline -> local playlist per D8) + client-side filter (Slint 1.16 has no string contains, routed through a Rust callback) + success toasts. Playlist importer (1:1 Tauri port): - New headless crate qbz-playlist-import (Spotify/Apple/Tidal/Deezer scrapers, Qobuz matcher, importer, progress sink, shared http client; copy-not-move from src-tauri, zero tauri deps; 40 unit tests green). - PlaylistImportModal (two-step fetch-preview -> import with live progress bar / log / summary) + controller + sidebar PLAYLISTS menu entry point. Reco logging staged behind TODO(reco-v1) markers (golden rule: playlist recommendations ship in Slint v1 once the reco engine is extracted to a shared crate). cc
This commit is contained in:
33 files changed
+5664
-129
No files matched your search
@@ -10,7 +10,8 @@ use qbz_models::{
|
||||
Album, Artist, ArtistAlbums, CoreEvent, DiscoverAlbum, DiscoverData, DiscoverPlaylistsResponse,
|
||||
DiscoverResponse, FrontendAdapter, GenreInfo, LabelExploreResponse, LabelGetListResponse,
|
||||
LabelListPage, LabelPageData, LabelStoryResponse, PageArtistResponse,
|
||||
MostPopularItem, Playlist, PlaylistTag, Quality, QueueState, QueueTrack, ReleasesGridResponse,
|
||||
MostPopularItem, Playlist, PlaylistDuplicateResult, PlaylistTag, Quality, QueueState,
|
||||
QueueTrack, ReleasesGridResponse,
|
||||
RepeatMode, SearchAllResults, SearchResultsPage, StreamUrl, Track, TracksContainer,
|
||||
UserSession,
|
||||
};
|
||||
@@ -1015,6 +1016,27 @@ impl<A: FrontendAdapter + Send + Sync + 'static> QbzCore<A> {
|
||||
.map_err(CoreError::Api)
|
||||
}
|
||||
|
||||
/// Check how many of `track_ids` are already in the Qobuz playlist
|
||||
/// `playlist_id`. Mirrors Tauri's `v2_check_playlist_duplicates`
|
||||
/// (commands_v2/playlists.rs): fetch the playlist's existing track ids and
|
||||
/// set-intersect with the input. This is Qobuz-tracks-into-Qobuz-playlist
|
||||
/// only — callers gate out local / Plex / local-playlist targets before
|
||||
/// calling (those never duplicate-check, mirroring the Tauri flow).
|
||||
pub async fn check_playlist_duplicates(
|
||||
&self,
|
||||
playlist_id: u64,
|
||||
track_ids: &[u64],
|
||||
) -> Result<PlaylistDuplicateResult, CoreError> {
|
||||
let client = self.client.read().await;
|
||||
let client = client.as_ref().ok_or(CoreError::NotInitialized)?;
|
||||
|
||||
let playlist = client
|
||||
.get_playlist_track_ids(playlist_id)
|
||||
.await
|
||||
.map_err(CoreError::Api)?;
|
||||
Ok(compute_playlist_duplicates(&playlist.track_ids, track_ids))
|
||||
}
|
||||
|
||||
/// Remove tracks from playlist
|
||||
pub async fn remove_tracks_from_playlist(
|
||||
&self,
|
||||
@@ -2336,6 +2358,28 @@ fn shuffle_with_seed<T>(items: &mut Vec<T>, seed_mbid: &str, secondary_tag: Opti
|
||||
}
|
||||
}
|
||||
|
||||
/// Pure set-intersection behind [`QbzCore::check_playlist_duplicates`] — split
|
||||
/// out so the duplicate logic is unit-testable without a live Qobuz client.
|
||||
/// `existing` = the playlist's current track ids; `track_ids` = the ids the
|
||||
/// user wants to add. Returns the Tauri-shaped result (total checked, how many
|
||||
/// are already present, and the set of those duplicate ids).
|
||||
pub(crate) fn compute_playlist_duplicates(
|
||||
existing: &[u64],
|
||||
track_ids: &[u64],
|
||||
) -> PlaylistDuplicateResult {
|
||||
let existing_set: std::collections::HashSet<u64> = existing.iter().copied().collect();
|
||||
let duplicate_track_ids: std::collections::HashSet<u64> = track_ids
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|id| existing_set.contains(id))
|
||||
.collect();
|
||||
PlaylistDuplicateResult {
|
||||
total_tracks: track_ids.len(),
|
||||
duplicate_count: duplicate_track_ids.len(),
|
||||
duplicate_track_ids,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -2361,4 +2405,33 @@ mod tests {
|
||||
assert_eq!(out.artists.total, 1);
|
||||
assert!(out.most_popular.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_playlist_duplicates_intersects_input_with_existing() {
|
||||
// Existing playlist has 10, 20, 30. Adding 20, 30, 40, 50:
|
||||
// 20 and 30 are duplicates; 40 and 50 are new.
|
||||
let existing = [10u64, 20, 30];
|
||||
let to_add = [20u64, 30, 40, 50];
|
||||
let r = compute_playlist_duplicates(&existing, &to_add);
|
||||
assert_eq!(r.total_tracks, 4);
|
||||
assert_eq!(r.duplicate_count, 2);
|
||||
assert!(r.duplicate_track_ids.contains(&20));
|
||||
assert!(r.duplicate_track_ids.contains(&30));
|
||||
assert!(!r.duplicate_track_ids.contains(&40));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_playlist_duplicates_none_when_disjoint() {
|
||||
let r = compute_playlist_duplicates(&[1u64, 2, 3], &[4u64, 5]);
|
||||
assert_eq!(r.total_tracks, 2);
|
||||
assert_eq!(r.duplicate_count, 0);
|
||||
assert!(r.duplicate_track_ids.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_playlist_duplicates_empty_input() {
|
||||
let r = compute_playlist_duplicates(&[1u64, 2, 3], &[]);
|
||||
assert_eq!(r.total_tracks, 0);
|
||||
assert_eq!(r.duplicate_count, 0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user