From 0f8bba5f8942825bc3b04dbf3cc24a2353466ff3 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Tue, 10 Feb 2026 01:48:37 -0600 Subject: [PATCH] feat: add playlist tags endpoint and DiscoverPlaylistsBrowseView component --- src-tauri/src/api/client.rs | 44 + src-tauri/src/api/endpoints.rs | 1 + src-tauri/src/api/models.rs | 16 + src-tauri/src/commands/search.rs | 14 +- src-tauri/src/lib.rs | 1 + .../views/DiscoverPlaylistsBrowseView.svelte | 779 ++++++++++++++++++ src/lib/stores/genreFilterStore.ts | 8 +- 7 files changed, 861 insertions(+), 2 deletions(-) create mode 100644 src/lib/components/views/DiscoverPlaylistsBrowseView.svelte diff --git a/src-tauri/src/api/client.rs b/src-tauri/src/api/client.rs index b31c2ba48..e8591787b 100644 --- a/src-tauri/src/api/client.rs +++ b/src-tauri/src/api/client.rs @@ -644,6 +644,50 @@ impl QobuzClient { Ok(response) } + /// Get playlist tags with localized names + pub async fn get_playlist_tags(&self) -> Result> { + let url = endpoints::build_url(paths::PLAYLIST_GET_TAGS); + + let http_response = self + .http + .get(&url) + .headers(self.authenticated_headers().await?) + .send() + .await?; + log::info!("[API] get_playlist_tags status={}", http_response.status()); + + let raw: PlaylistTagsResponse = http_response.json().await?; + + // Get current locale (e.g., "en", "es", "fr", "de") + let locale = self.locale().await; + let lang = locale.split('-').next().unwrap_or("en"); + + // Convert raw tags to PlaylistTag with localized name + let tags: Vec = raw + .tags + .into_iter() + .filter(|tag| tag.is_discover.as_deref() == Some("true")) + .filter_map(|tag| { + // Parse name_json to get localized name + let name_map: serde_json::Value = + serde_json::from_str(&tag.name_json).ok()?; + let name = name_map + .get(lang) + .or_else(|| name_map.get("en")) + .and_then(|v| v.as_str()) + .map(|s| s.to_string())?; + let id = tag.featured_tag_id + .as_ref() + .and_then(|s| s.parse::().ok()) + .unwrap_or(0); + Some(PlaylistTag { id, slug: tag.slug, name }) + }) + .collect(); + + log::debug!("[API] get_playlist_tags: {} tags", tags.len()); + Ok(tags) + } + /// Get track by ID pub async fn get_track(&self, track_id: u64) -> Result { let url = endpoints::build_url(paths::TRACK_GET); diff --git a/src-tauri/src/api/endpoints.rs b/src-tauri/src/api/endpoints.rs index 1d8b0c151..796b41a48 100644 --- a/src-tauri/src/api/endpoints.rs +++ b/src-tauri/src/api/endpoints.rs @@ -35,6 +35,7 @@ pub mod paths { pub const PLAYLIST_ADD_TRACKS: &str = "/playlist/addTracks"; pub const PLAYLIST_DELETE_TRACKS: &str = "/playlist/deleteTracks"; pub const PLAYLIST_UPDATE: &str = "/playlist/update"; + pub const PLAYLIST_GET_TAGS: &str = "/playlist/getTags"; // Favorites pub const FAVORITE_GET_USER_FAVORITES: &str = "/favorite/getUserFavorites"; diff --git a/src-tauri/src/api/models.rs b/src-tauri/src/api/models.rs index 493f3e2cd..7caa2dab3 100644 --- a/src-tauri/src/api/models.rs +++ b/src-tauri/src/api/models.rs @@ -449,6 +449,22 @@ pub struct PlaylistTag { pub name: String, } +/// Raw playlist tag from /playlist/getTags (has localized name_json) +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RawPlaylistTag { + pub slug: String, + pub name_json: String, + pub position: Option, + pub is_discover: Option, + pub featured_tag_id: Option, +} + +/// Response from /playlist/getTags +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PlaylistTagsResponse { + pub tags: Vec, +} + /// Response from discover/playlists endpoint /// Note: This endpoint returns items directly at root level (not wrapped in "playlists") #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src-tauri/src/commands/search.rs b/src-tauri/src/commands/search.rs index 7b5120e1e..5c985c3e3 100644 --- a/src-tauri/src/commands/search.rs +++ b/src-tauri/src/commands/search.rs @@ -2,7 +2,7 @@ use tauri::State; -use crate::api::{endpoints, endpoints::paths, Album, Artist, ArtistAlbums, DiscoverAlbum, DiscoverData, DiscoverResponse, DiscoverPlaylistsResponse, LabelDetail, PageArtistResponse, Playlist, ReleasesGridResponse, SearchResultsPage, Track, TracksContainer}; +use crate::api::{endpoints, endpoints::paths, Album, Artist, ArtistAlbums, DiscoverAlbum, DiscoverData, DiscoverResponse, DiscoverPlaylistsResponse, LabelDetail, PageArtistResponse, Playlist, PlaylistTag, ReleasesGridResponse, SearchResultsPage, Track, TracksContainer}; use crate::api_cache::ApiCacheState; use crate::artist_blacklist::BlacklistState; use crate::AppState; @@ -694,6 +694,18 @@ pub async fn get_discover_playlists( .map_err(|e| e.to_string()) } +/// Get playlist tags (localized names from /playlist/getTags) +#[tauri::command] +pub async fn get_playlist_tags( + state: State<'_, AppState>, +) -> Result, String> { + let client = state.client.read().await; + client + .get_playlist_tags() + .await + .map_err(|e| e.to_string()) +} + /// Get discover albums from a browse endpoint (newReleases, idealDiscography, mostStreamed) #[tauri::command] pub async fn get_discover_albums( diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ab51461c0..be01f48c7 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -503,6 +503,7 @@ pub fn run() { commands::get_genres, commands::get_discover_index, commands::get_discover_playlists, + commands::get_playlist_tags, commands::get_discover_albums, commands::get_track, commands::get_artist, diff --git a/src/lib/components/views/DiscoverPlaylistsBrowseView.svelte b/src/lib/components/views/DiscoverPlaylistsBrowseView.svelte new file mode 100644 index 000000000..c1528caab --- /dev/null +++ b/src/lib/components/views/DiscoverPlaylistsBrowseView.svelte @@ -0,0 +1,779 @@ + + +
+ +
+
+ +

{$t('discover.qobuzPlaylists')}

+
+
+
+ + + {#if searchQuery} + + {/if} +
+ +
+ + +
+
+
+ + + {#if tags.length > 0} +
+
+ + {#each tags as tag (tag.id)} + + {/each} +
+
+ {/if} + + +
+ {#if isLoading} +
+
+ {#each { length: 12 } as _} + {#if viewMode === 'grid'} +
+
+
+
+
+ {:else} +
+
+
+
+
+
+
+ {/if} + {/each} +
+
+ {:else if getFilteredPlaylists().length === 0} +
+

{$t('discover.noPlaylistResults')}

+
+ {:else if viewMode === 'grid'} + +
+ {#each getFilteredPlaylists() as playlist (playlist.id)} +
+ onPlaylistClick(playlist.id) : undefined} + onPlay={onPlaylistPlay ? () => onPlaylistPlay(playlist.id) : undefined} + onPlayNext={onPlaylistPlayNext ? () => onPlaylistPlayNext(playlist.id) : undefined} + onPlayLater={onPlaylistPlayLater ? () => onPlaylistPlayLater(playlist.id) : undefined} + onCopyToLibrary={onPlaylistCopyToLibrary ? () => onPlaylistCopyToLibrary(playlist.id) : undefined} + onShareQobuz={onPlaylistShareQobuz ? () => onPlaylistShareQobuz(playlist.id) : undefined} + /> + {#if getFirstTagName(playlist)} +
{getFirstTagName(playlist)}
+ {/if} +
+ {/each} +
+ {:else} + +
+ {#each getFilteredPlaylists() as playlist (playlist.id)} + + {/if} + {#if onPlaylistCopyToLibrary} + + {/if} +
+ + {/each} +
+ {/if} + + {#if isLoadingMore} +
+
+ {$t('discover.loadingMore')} +
+ {/if} +
+ + + diff --git a/src/lib/stores/genreFilterStore.ts b/src/lib/stores/genreFilterStore.ts index e13ce1b40..76f6d58d4 100644 --- a/src/lib/stores/genreFilterStore.ts +++ b/src/lib/stores/genreFilterStore.ts @@ -20,7 +20,7 @@ export interface GenreTreeNode { loading?: boolean; } -export type GenreFilterContext = 'home' | 'favorites' | 'discover-new-releases' | 'discover-ideal-discography' | 'discover-top-albums' | 'discover-qobuzissimes' | 'discover-albums-of-the-week' | 'discover-press-accolades'; +export type GenreFilterContext = 'home' | 'favorites' | 'discover-new-releases' | 'discover-ideal-discography' | 'discover-top-albums' | 'discover-qobuzissimes' | 'discover-albums-of-the-week' | 'discover-press-accolades' | 'discover-playlists'; interface ContextState { selectedGenreIds: Set; @@ -46,6 +46,7 @@ const STORAGE_KEYS: Record = { 'discover-qobuzissimes': 'qbz_genre_filter_discover_qobuzissimes', 'discover-albums-of-the-week': 'qbz_genre_filter_discover_albums_of_the_week', 'discover-press-accolades': 'qbz_genre_filter_discover_press_accolades', + 'discover-playlists': 'qbz_genre_filter_discover_playlists', }; const GENRE_CACHE_KEY = 'qbz_genre_cache'; @@ -139,6 +140,11 @@ const state: GenreFilterState = { rememberSelection: true, listeners: new Set(), }, + 'discover-playlists': { + selectedGenreIds: new Set(), + rememberSelection: true, + listeners: new Set(), + }, }, };