feat(home): add Qobuz discover playlists section with tag filter
- Add backend endpoint for /discover/playlists API - Add PlaylistTagFilter dropdown component for filtering by genre - Add QobuzPlaylistCard with CSS blur background effect (color-thief style) - Add HorizontalScrollRow header snippet for custom headers with scroll controls - Add session cache store for caching API responses - Add i18n keys for playlist filter and discover section cc
This commit is contained in:
1 parent
9341e9ee19
commit
deaffa183d
15 files changed
+1608
-63
No files matched your search
@@ -452,6 +452,100 @@ impl QobuzClient {
|
||||
Ok(serde_json::from_value(genres.clone())?)
|
||||
}
|
||||
|
||||
/// Get discover index (home page content: playlists, ideal discography, etc.)
|
||||
pub async fn get_discover_index(
|
||||
&self,
|
||||
genre_ids: Option<Vec<u64>>,
|
||||
) -> Result<DiscoverResponse> {
|
||||
let url = endpoints::build_url(paths::DISCOVER_INDEX);
|
||||
let mut query: Vec<(&str, String)> = vec![];
|
||||
|
||||
// Add genre_ids as comma-separated list if provided
|
||||
if let Some(gids) = genre_ids {
|
||||
if !gids.is_empty() {
|
||||
let ids_str = gids.iter().map(|id| id.to_string()).collect::<Vec<_>>().join(",");
|
||||
query.push(("genre_ids", ids_str));
|
||||
}
|
||||
}
|
||||
|
||||
let response: Value = self
|
||||
.http
|
||||
.get(&url)
|
||||
.header("X-App-Id", self.app_id().await?)
|
||||
.header("X-User-Auth-Token", self.auth_token().await?)
|
||||
.query(&query)
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
// Debug: log the response structure
|
||||
if let Some(obj) = response.as_object() {
|
||||
log::info!("Discover API response keys: {:?}", obj.keys().collect::<Vec<_>>());
|
||||
if let Some(err) = obj.get("message") {
|
||||
log::error!("Discover API error: {:?}", err);
|
||||
}
|
||||
if let Some(code) = obj.get("code") {
|
||||
log::error!("Discover API error code: {:?}", code);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(serde_json::from_value(response)?)
|
||||
}
|
||||
|
||||
/// Get discover playlists with optional tag filter
|
||||
/// Example: tags=label, tags=partner
|
||||
pub async fn get_discover_playlists(
|
||||
&self,
|
||||
tag: Option<String>,
|
||||
limit: Option<u32>,
|
||||
offset: Option<u32>,
|
||||
) -> Result<DiscoverPlaylistsResponse> {
|
||||
let url = endpoints::build_url(paths::DISCOVER_PLAYLISTS);
|
||||
let mut query: Vec<(&str, String)> = vec![];
|
||||
|
||||
// Add tag filter if provided (e.g., "label", "partner")
|
||||
if let Some(ref t) = tag {
|
||||
query.push(("tags", t.clone()));
|
||||
}
|
||||
|
||||
// Add limit (default 20)
|
||||
let lim = limit.unwrap_or(20);
|
||||
query.push(("limit", lim.to_string()));
|
||||
|
||||
// Add offset (default 0)
|
||||
let off = offset.unwrap_or(0);
|
||||
query.push(("offset", off.to_string()));
|
||||
|
||||
log::debug!("[API] get_discover_playlists URL: {} query: {:?}", url, query);
|
||||
|
||||
// First get raw JSON to debug structure
|
||||
let raw_response: serde_json::Value = self
|
||||
.http
|
||||
.get(&url)
|
||||
.header("X-App-Id", self.app_id().await?)
|
||||
.header("X-User-Auth-Token", self.auth_token().await?)
|
||||
.query(&query)
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
log::debug!("[API] get_discover_playlists raw response keys: {:?}", raw_response.as_object().map(|o| o.keys().collect::<Vec<_>>()));
|
||||
|
||||
// Try to parse as expected structure
|
||||
let response: DiscoverPlaylistsResponse = serde_json::from_value(raw_response.clone())
|
||||
.map_err(|e| {
|
||||
log::error!("[API] Failed to parse discover playlists response: {}", e);
|
||||
log::error!("[API] Raw response: {}", serde_json::to_string_pretty(&raw_response).unwrap_or_default());
|
||||
e
|
||||
})?;
|
||||
|
||||
log::debug!("[API] get_discover_playlists response: {} playlists", response.items.len());
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
/// Get track by ID
|
||||
pub async fn get_track(&self, track_id: u64) -> Result<Track> {
|
||||
let url = endpoints::build_url(paths::TRACK_GET);
|
||||
@@ -468,6 +562,29 @@ impl QobuzClient {
|
||||
Ok(serde_json::from_value(response)?)
|
||||
}
|
||||
|
||||
/// Get artist by ID (basic info only - no albums, faster response)
|
||||
pub async fn get_artist_basic(&self, artist_id: u64) -> Result<Artist> {
|
||||
let url = endpoints::build_url(paths::ARTIST_GET);
|
||||
let locale = self.locale().await;
|
||||
let query = vec![
|
||||
("artist_id", artist_id.to_string()),
|
||||
("lang", locale),
|
||||
// No "extra" parameter = only basic info (id, name, image)
|
||||
];
|
||||
|
||||
let response: Value = self
|
||||
.http
|
||||
.get(&url)
|
||||
.header("X-App-Id", self.app_id().await?)
|
||||
.query(&query)
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
Ok(serde_json::from_value(response)?)
|
||||
}
|
||||
|
||||
/// Get artist by ID
|
||||
pub async fn get_artist(
|
||||
&self,
|
||||
|
||||
@@ -45,6 +45,10 @@ pub mod paths {
|
||||
|
||||
// Catalog (combined search)
|
||||
pub const CATALOG_SEARCH: &str = "/catalog/search";
|
||||
|
||||
// Discover (home page content)
|
||||
pub const DISCOVER_INDEX: &str = "/discover/index";
|
||||
pub const DISCOVER_PLAYLISTS: &str = "/discover/playlists";
|
||||
}
|
||||
|
||||
/// Build full URL for an endpoint
|
||||
|
||||
+126
-4
@@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize};
|
||||
#[repr(u32)]
|
||||
pub enum Quality {
|
||||
Mp3 = 5,
|
||||
Lossless = 6, // 16-bit/44.1kHz (CD Quality)
|
||||
HiRes = 7, // 24-bit/≤96kHz
|
||||
UltraHiRes = 27, // 24-bit/>96kHz
|
||||
Lossless = 6, // 16-bit/44.1kHz (CD Quality)
|
||||
HiRes = 7, // 24-bit/≤96kHz
|
||||
UltraHiRes = 27, // 24-bit/>96kHz
|
||||
}
|
||||
|
||||
impl Quality {
|
||||
@@ -38,7 +38,12 @@ impl Quality {
|
||||
|
||||
/// Quality levels in descending order for fallback
|
||||
pub fn fallback_order() -> &'static [Quality] {
|
||||
&[Quality::UltraHiRes, Quality::HiRes, Quality::Lossless, Quality::Mp3]
|
||||
&[
|
||||
Quality::UltraHiRes,
|
||||
Quality::HiRes,
|
||||
Quality::Lossless,
|
||||
Quality::Mp3,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,3 +349,120 @@ pub struct Favorites {
|
||||
pub tracks: Option<SearchResultsPage<Track>>,
|
||||
pub artists: Option<SearchResultsPage<Artist>>,
|
||||
}
|
||||
|
||||
// ============ Discover API Models ============
|
||||
|
||||
/// Discover index response
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverResponse {
|
||||
pub containers: DiscoverContainers,
|
||||
}
|
||||
|
||||
/// All discover containers
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverContainers {
|
||||
pub playlists: Option<DiscoverContainer<DiscoverPlaylist>>,
|
||||
pub ideal_discography: Option<DiscoverContainer<DiscoverAlbum>>,
|
||||
pub playlists_tags: Option<DiscoverContainer<PlaylistTag>>,
|
||||
pub new_releases: Option<DiscoverContainer<DiscoverAlbum>>,
|
||||
}
|
||||
|
||||
/// Generic discover container
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverContainer<T> {
|
||||
pub id: String,
|
||||
pub data: DiscoverData<T>,
|
||||
}
|
||||
|
||||
/// Generic discover data with items
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverData<T> {
|
||||
pub has_more: bool,
|
||||
pub items: Vec<T>,
|
||||
}
|
||||
|
||||
/// Playlist from discover endpoint (different structure than regular Playlist)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverPlaylist {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub owner: PlaylistOwner,
|
||||
pub image: DiscoverPlaylistImage,
|
||||
pub description: Option<String>,
|
||||
pub duration: u32,
|
||||
pub tracks_count: u32,
|
||||
pub genres: Option<Vec<PlaylistGenre>>,
|
||||
pub tags: Option<Vec<PlaylistTag>>,
|
||||
}
|
||||
|
||||
/// Playlist image structure from discover (has rectangle and covers)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverPlaylistImage {
|
||||
pub rectangle: Option<String>,
|
||||
pub covers: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
/// Playlist tag (for filtering)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PlaylistTag {
|
||||
pub id: u64,
|
||||
pub slug: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// Response from discover/playlists endpoint
|
||||
/// Note: This endpoint returns items directly at root level (not wrapped in "playlists")
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverPlaylistsResponse {
|
||||
pub has_more: bool,
|
||||
pub items: Vec<DiscoverPlaylist>,
|
||||
}
|
||||
|
||||
/// Album from discover endpoint
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverAlbum {
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
pub version: Option<String>,
|
||||
pub track_count: Option<u32>,
|
||||
pub duration: Option<u32>,
|
||||
pub parental_warning: Option<bool>,
|
||||
pub image: DiscoverAlbumImage,
|
||||
pub artists: Vec<DiscoverArtist>,
|
||||
pub label: Option<Label>,
|
||||
pub genre: Option<Genre>,
|
||||
pub dates: Option<DiscoverAlbumDates>,
|
||||
pub audio_info: Option<DiscoverAudioInfo>,
|
||||
}
|
||||
|
||||
/// Album image from discover endpoint
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverAlbumImage {
|
||||
pub small: Option<String>,
|
||||
pub thumbnail: Option<String>,
|
||||
pub large: Option<String>,
|
||||
}
|
||||
|
||||
/// Artist in discover album
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverArtist {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub roles: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
/// Album dates from discover
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverAlbumDates {
|
||||
pub download: Option<String>,
|
||||
pub original: Option<String>,
|
||||
pub stream: Option<String>,
|
||||
}
|
||||
|
||||
/// Audio info from discover album
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoverAudioInfo {
|
||||
pub maximum_sampling_rate: Option<f64>,
|
||||
pub maximum_bit_depth: Option<u32>,
|
||||
pub maximum_channel_count: Option<u32>,
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use tauri::State;
|
||||
|
||||
use crate::api::{endpoints, endpoints::paths, Album, Artist, ArtistAlbums, LabelDetail, Playlist, SearchResultsPage, Track, TracksContainer};
|
||||
use crate::api::{endpoints, endpoints::paths, Album, Artist, ArtistAlbums, DiscoverResponse, DiscoverPlaylistsResponse, LabelDetail, Playlist, SearchResultsPage, Track, TracksContainer};
|
||||
use crate::api_cache::ApiCacheState;
|
||||
use crate::artist_blacklist::BlacklistState;
|
||||
use crate::AppState;
|
||||
@@ -416,6 +416,50 @@ pub async fn get_artist(
|
||||
Ok(artist)
|
||||
}
|
||||
|
||||
/// Get artist basic info only (no albums - faster for lists/cards)
|
||||
#[tauri::command]
|
||||
pub async fn get_artist_basic(
|
||||
artist_id: u64,
|
||||
state: State<'_, AppState>,
|
||||
cache_state: State<'_, ApiCacheState>,
|
||||
) -> Result<Artist, String> {
|
||||
log::debug!("Command: get_artist_basic {}", artist_id);
|
||||
|
||||
// Get current locale
|
||||
let locale = {
|
||||
let client = state.client.lock().await;
|
||||
client.get_locale().await
|
||||
};
|
||||
|
||||
// Check cache first (reuse same cache - basic response works for both)
|
||||
{
|
||||
let cache = cache_state.cache.lock().await;
|
||||
if let Some(cached_data) = cache.get_artist(artist_id, &locale, None)? {
|
||||
log::debug!("Cache hit for artist_basic {} (locale: {})", artist_id, locale);
|
||||
return serde_json::from_str(&cached_data)
|
||||
.map_err(|e| format!("Failed to parse cached artist: {}", e));
|
||||
}
|
||||
}
|
||||
|
||||
// Cache miss - fetch from API (without albums - much faster)
|
||||
log::debug!("Cache miss for artist_basic {} (locale: {}), fetching from API", artist_id, locale);
|
||||
let client = state.client.lock().await;
|
||||
let artist = client
|
||||
.get_artist_basic(artist_id)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
// Cache the result
|
||||
{
|
||||
let cache = cache_state.cache.lock().await;
|
||||
let json = serde_json::to_string(&artist)
|
||||
.map_err(|e| format!("Failed to serialize artist: {}", e))?;
|
||||
cache.set_artist(artist_id, &locale, &json)?;
|
||||
}
|
||||
|
||||
Ok(artist)
|
||||
}
|
||||
|
||||
/// Get artist detail with albums, playlists, and appears-on tracks
|
||||
/// Fetches 1000 albums initially to ensure each album type section
|
||||
/// (Discography, EPs, Live, etc.) has enough albums loaded
|
||||
@@ -552,3 +596,35 @@ pub async fn get_genres(
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Get discover index (home page content: playlists, ideal discography, etc.)
|
||||
#[tauri::command]
|
||||
pub async fn get_discover_index(
|
||||
genre_ids: Option<Vec<u64>>,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<DiscoverResponse, String> {
|
||||
log::debug!("Command: get_discover_index genre_ids={:?}", genre_ids);
|
||||
|
||||
let client = state.client.lock().await;
|
||||
client
|
||||
.get_discover_index(genre_ids)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Get discover playlists with optional tag filter
|
||||
#[tauri::command]
|
||||
pub async fn get_discover_playlists(
|
||||
tag: Option<String>,
|
||||
limit: Option<u32>,
|
||||
offset: Option<u32>,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<DiscoverPlaylistsResponse, String> {
|
||||
log::debug!("Command: get_discover_playlists tag={:?} limit={:?} offset={:?}", tag, limit, offset);
|
||||
|
||||
let client = state.client.lock().await;
|
||||
client
|
||||
.get_discover_playlists(tag, limit, offset)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
@@ -529,8 +529,11 @@ pub fn run() {
|
||||
commands::get_album,
|
||||
commands::get_featured_albums,
|
||||
commands::get_genres,
|
||||
commands::get_discover_index,
|
||||
commands::get_discover_playlists,
|
||||
commands::get_track,
|
||||
commands::get_artist,
|
||||
commands::get_artist_basic,
|
||||
commands::get_artist_detail,
|
||||
commands::get_artist_tracks,
|
||||
commands::get_artist_albums,
|
||||
|
||||
Reference in new issue
Block a user