feat(playlist): Qobuz playlist Follow + Copy + internal favorite reflect
The heart on a Qobuz playlist detail was wired to Qobuz /favorite/create, which does not accept playlist_ids, so it persisted nowhere and never reflected in the library. Rewire it to the INTERNAL library favorite (db.set_playlist_favorite, mirroring the Favorites card + Tauri's v2_playlist_set_favorite) and seed it on open. Add the two missing actions on a non-owned Qobuz playlist: - Copy to library: clone it (create + add all tracks, carrying the source artwork + attribution) as an internal owned copy. - Follow on Qobuz: subscribe/unsubscribe via new qbz-core passthroughs to the existing client subscribe_playlist/unsubscribe_playlist. Surface hearted-but-not-owned playlists in Library>Playlists by merging the internal favorite ids into the manager list (they don't come back from get_user_playlists). Copies/follows already appear there (owned / subscribed). New PlaylistState.is-following / is-copied. cc
This commit is contained in:
5 files changed
+229
-11
No files matched your search
@@ -1197,6 +1197,29 @@ impl<A: FrontendAdapter + Send + Sync + 'static> QbzCore<A> {
|
||||
.map_err(CoreError::Api)
|
||||
}
|
||||
|
||||
/// Follow (subscribe to) a Qobuz playlist so it appears in the user's Qobuz
|
||||
/// account across every Qobuz client (and in their user-playlists list).
|
||||
pub async fn subscribe_playlist(&self, playlist_id: u64) -> Result<(), CoreError> {
|
||||
let client = self.client.read().await;
|
||||
let client = client.as_ref().ok_or(CoreError::NotInitialized)?;
|
||||
|
||||
client
|
||||
.subscribe_playlist(playlist_id)
|
||||
.await
|
||||
.map_err(CoreError::Api)
|
||||
}
|
||||
|
||||
/// Unfollow (unsubscribe from) a Qobuz playlist.
|
||||
pub async fn unsubscribe_playlist(&self, playlist_id: u64) -> Result<(), CoreError> {
|
||||
let client = self.client.read().await;
|
||||
let client = client.as_ref().ok_or(CoreError::NotInitialized)?;
|
||||
|
||||
client
|
||||
.unsubscribe_playlist(playlist_id)
|
||||
.await
|
||||
.map_err(CoreError::Api)
|
||||
}
|
||||
|
||||
/// Delete a playlist
|
||||
pub async fn delete_playlist(&self, playlist_id: u64) -> Result<(), CoreError> {
|
||||
let client = self.client.read().await;
|
||||
|
||||
@@ -590,6 +590,34 @@ export component PlaylistView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Follow on Qobuz (subscribe) — only a non-owned Qobuz
|
||||
// playlist; syncs to the user's Qobuz account.
|
||||
if !PlaylistState.is-local && !PlaylistState.is-owner: VerticalLayout {
|
||||
horizontal-stretch: 0;
|
||||
alignment: center;
|
||||
CircleAction {
|
||||
icon: @image-url("../assets/icons/user-plus.svg");
|
||||
active: PlaylistState.is-following;
|
||||
tooltip: PlaylistState.is-following ? @tr("Following on Qobuz") : @tr("Follow on Qobuz");
|
||||
clicked => {
|
||||
root.media-action("playlist", PlaylistState.id, "follow");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copy to your library — clone a non-owned Qobuz playlist
|
||||
// into your own playlists (hidden once copied).
|
||||
if !PlaylistState.is-local && !PlaylistState.is-owner
|
||||
&& !PlaylistState.is-copied: VerticalLayout {
|
||||
horizontal-stretch: 0;
|
||||
alignment: center;
|
||||
CircleAction {
|
||||
icon: @image-url("../assets/icons/copy.svg");
|
||||
tooltip: @tr("Copy to your library");
|
||||
clicked => {
|
||||
root.media-action("playlist", PlaylistState.id, "copy");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Make the whole playlist available offline —
|
||||
// resolves Qobuz membership, hidden for LOCAL ones.
|
||||
if !PlaylistState.is-local: VerticalLayout {
|
||||
|
||||
@@ -1860,6 +1860,12 @@ export global PlaylistState {
|
||||
in property <bool> is-favorite: false;
|
||||
// True when the playlist is one of the user's own (editable).
|
||||
in property <bool> is-owner: false;
|
||||
// Followed (subscribed) on Qobuz — an account-level follow that syncs
|
||||
// across Qobuz clients, distinct from the internal favorite heart.
|
||||
in property <bool> is-following: false;
|
||||
// Already copied into the user's own playlists this session (hides the
|
||||
// Copy action so it isn't duplicated).
|
||||
in property <bool> is-copied: false;
|
||||
// LOCAL playlist (id "local:<uuid>", library.db entity — never on
|
||||
// Qobuz). Qobuz-bound header actions (favorite / cache) hide; the
|
||||
// "Upload to Qobuz" action appears when not offline-only.
|
||||
|
||||
+140
-11
@@ -2826,10 +2826,20 @@ fn navigate_playlist(
|
||||
// plex rows = tokenized Plex thumbs.
|
||||
let (http_jobs, local_jobs, plex_jobs) = playlist::artwork_jobs(&data);
|
||||
let pid = data.id.clone();
|
||||
// Seed the INTERNAL favorite heart from the library db (the open
|
||||
// handler otherwise only sets is_owner, so the heart was always
|
||||
// un-filled on open).
|
||||
let fav = pid.parse::<u64>().ok().is_some_and(|id| {
|
||||
crate::library_db::with_db(|db| db.get_favorite_playlist_ids())
|
||||
.unwrap_or_default()
|
||||
.contains(&id)
|
||||
});
|
||||
let _ = weak.upgrade_in_event_loop(move |w| {
|
||||
playlist::apply(&w, data);
|
||||
let owned = sidebar::contains(&w, &pid);
|
||||
w.global::<PlaylistState>().set_is_owner(owned);
|
||||
let st = w.global::<PlaylistState>();
|
||||
st.set_is_owner(owned);
|
||||
st.set_is_favorite(fav);
|
||||
});
|
||||
if !http_jobs.is_empty() {
|
||||
artwork::spawn_loads(http_jobs, weak.clone(), image_cache.clone());
|
||||
@@ -9002,27 +9012,146 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
}
|
||||
("playlist", "favorite") => {
|
||||
// Favorite/unfavorite the open playlist.
|
||||
// Favorite/unfavorite the open playlist. This is an INTERNAL
|
||||
// qbz library flag (Qobuz /favorite/create does NOT accept
|
||||
// playlist_ids), mirroring the Favorites-card toggle and
|
||||
// Tauri's v2_playlist_set_favorite. Surfaced in
|
||||
// Favorites>Playlists + Library>Playlists.
|
||||
if let Some(w) = weak.upgrade() {
|
||||
let pid = w.global::<PlaylistState>().get_id().to_string();
|
||||
// LOCAL playlists have no Qobuz favorite — the UI
|
||||
// hides the button; guard the call path too (the
|
||||
// favorite endpoint takes the id as a string, so a
|
||||
// "local:" id COULD otherwise leak through).
|
||||
if local_playlist::is_local_id(&pid) {
|
||||
return;
|
||||
}
|
||||
let Ok(pid_u64) = pid.parse::<u64>() else {
|
||||
return;
|
||||
};
|
||||
let was_fav = w.global::<PlaylistState>().get_is_favorite();
|
||||
w.global::<PlaylistState>().set_is_favorite(!was_fav);
|
||||
let new_fav = !was_fav;
|
||||
w.global::<PlaylistState>().set_is_favorite(new_fav);
|
||||
let weak2 = weak.clone();
|
||||
handle.spawn_blocking(move || {
|
||||
let ok = crate::library_db::with_db(|db| {
|
||||
db.set_playlist_favorite(pid_u64, new_fav)
|
||||
});
|
||||
if !matches!(ok, Some(Ok(()))) {
|
||||
log::error!("[qbz-slint] toggle playlist favorite failed");
|
||||
let _ = weak2.upgrade_in_event_loop(move |w| {
|
||||
w.global::<PlaylistState>().set_is_favorite(was_fav);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
("playlist", "copy") => {
|
||||
// Copy a Qobuz playlist into the user's own playlists
|
||||
// (create + add every track). INTERNAL — mirrors Tauri's
|
||||
// (mis-named) v2_subscribe_playlist. The copy is owned, so it
|
||||
// shows up in Library>Playlists via get_user_playlists.
|
||||
if let Some(w) = weak.upgrade() {
|
||||
let pid = w.global::<PlaylistState>().get_id().to_string();
|
||||
if local_playlist::is_local_id(&pid) {
|
||||
return;
|
||||
}
|
||||
let Ok(pid_u64) = pid.parse::<u64>() else {
|
||||
return;
|
||||
};
|
||||
let runtime = runtime.clone();
|
||||
let weak2 = weak.clone();
|
||||
handle.spawn(async move {
|
||||
let res = if was_fav {
|
||||
runtime.core().remove_favorite("playlist", &pid).await
|
||||
let source = match runtime.core().get_playlist(pid_u64).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
log::error!("[qbz-slint] copy playlist: get source failed: {e}");
|
||||
crate::toast::error_weak(&weak2, "Failed to copy playlist");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let track_ids: Vec<u64> = source
|
||||
.tracks
|
||||
.as_ref()
|
||||
.map(|t| t.items.iter().map(|track| track.id).collect())
|
||||
.unwrap_or_default();
|
||||
if track_ids.is_empty() {
|
||||
crate::toast::error_weak(&weak2, "Playlist has no tracks to copy");
|
||||
return;
|
||||
}
|
||||
let attribution = format!(
|
||||
"\n\n---\nOriginally curated by {} on Qobuz",
|
||||
source.owner.name
|
||||
);
|
||||
let new_description = match source.description {
|
||||
Some(ref d) if !d.is_empty() => Some(format!("{d}{attribution}")),
|
||||
_ => Some(attribution.trim_start().to_string()),
|
||||
};
|
||||
let new_playlist = match runtime
|
||||
.core()
|
||||
.create_playlist(&source.name, new_description.as_deref(), false)
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
log::error!("[qbz-slint] copy playlist: create failed: {e}");
|
||||
crate::toast::error_weak(&weak2, "Failed to copy playlist");
|
||||
return;
|
||||
}
|
||||
};
|
||||
if let Err(e) = runtime
|
||||
.core()
|
||||
.add_tracks_to_playlist(new_playlist.id, &track_ids)
|
||||
.await
|
||||
{
|
||||
log::error!("[qbz-slint] copy playlist: add tracks failed: {e}");
|
||||
}
|
||||
// Best-effort: carry over the source artwork.
|
||||
if let Some(img) =
|
||||
source.images.as_ref().and_then(|i| i.first()).cloned()
|
||||
{
|
||||
let new_id = new_playlist.id;
|
||||
let _ = tokio::task::spawn_blocking(move || {
|
||||
crate::library_db::with_db(|db| {
|
||||
db.update_playlist_artwork(new_id, Some(img.as_str()))
|
||||
});
|
||||
})
|
||||
.await;
|
||||
}
|
||||
let _ = weak2.upgrade_in_event_loop(move |w| {
|
||||
w.global::<PlaylistState>().set_is_copied(true);
|
||||
crate::toast::success(&w, "Copied to your library");
|
||||
});
|
||||
crate::playback::refresh_sidebar(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
("playlist", "follow") => {
|
||||
// Follow/unfollow on Qobuz (subscribe). Appears in the user's
|
||||
// Qobuz account across clients and in Library>Playlists via
|
||||
// get_user_playlists (as a non-owned subscribed playlist).
|
||||
if let Some(w) = weak.upgrade() {
|
||||
let pid = w.global::<PlaylistState>().get_id().to_string();
|
||||
if local_playlist::is_local_id(&pid) {
|
||||
return;
|
||||
}
|
||||
let Ok(pid_u64) = pid.parse::<u64>() else {
|
||||
return;
|
||||
};
|
||||
let was_following = w.global::<PlaylistState>().get_is_following();
|
||||
let make = !was_following;
|
||||
w.global::<PlaylistState>().set_is_following(make);
|
||||
let runtime = runtime.clone();
|
||||
let weak2 = weak.clone();
|
||||
handle.spawn(async move {
|
||||
let res = if make {
|
||||
runtime.core().subscribe_playlist(pid_u64).await
|
||||
} else {
|
||||
runtime.core().add_favorite("playlist", &pid).await
|
||||
runtime.core().unsubscribe_playlist(pid_u64).await
|
||||
};
|
||||
if let Err(e) = res {
|
||||
log::error!("[qbz-slint] toggle playlist favorite failed: {e}");
|
||||
log::error!("[qbz-slint] toggle playlist follow failed: {e}");
|
||||
let _ = weak2.upgrade_in_event_loop(move |w| {
|
||||
w.global::<PlaylistState>().set_is_following(was_following);
|
||||
});
|
||||
} else {
|
||||
crate::playback::refresh_sidebar(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -209,6 +209,38 @@ where
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Surface INTERNAL favorites (hearted playlists) that are neither owned nor
|
||||
// subscribed — they don't come back from get_user_playlists, so without this
|
||||
// a favorited-but-not-followed Qobuz playlist would be invisible here.
|
||||
// Online only (offline can't fetch them); mirrors Favorites>Playlists.
|
||||
if !crate::offline_mode::engine().is_offline() {
|
||||
let fav_ids =
|
||||
crate::library_db::with_db(|db| db.get_favorite_playlist_ids()).unwrap_or_default();
|
||||
let known: std::collections::HashSet<u64> = playlists.iter().map(|p| p.id).collect();
|
||||
for fid in fav_ids {
|
||||
if known.contains(&fid) {
|
||||
continue;
|
||||
}
|
||||
if let Ok(p) = runtime.core().get_playlist(fid).await {
|
||||
let s = settings.get(&fid).cloned().unwrap_or_default();
|
||||
playlists.push(PmPlaylist {
|
||||
id: fid,
|
||||
name: p.name.clone(),
|
||||
tracks_count: p.tracks_count,
|
||||
duration: p.duration,
|
||||
local_count: local_counts.get(&fid).copied().unwrap_or(0),
|
||||
play_count: play_counts.get(&fid).copied().unwrap_or(0),
|
||||
is_favorite: true,
|
||||
is_hidden: s.hidden,
|
||||
folder_id: s.folder_id.filter(|f| folder_ids.contains(f)),
|
||||
position: s.position,
|
||||
cover_urls: cover_urls(&p),
|
||||
offline_available: snapshot_available.contains(&fid),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// D11.b — OFFLINE: the Qobuz fetch is gate-refused (empty), so the
|
||||
// reachable playlists are synthesized locally: the MIXED ones (>= 1
|
||||
// local sidecar row) plus — B8 — the snapshot-available ones (>= 1
|
||||
|
||||
Reference in new issue
Block a user