feat: add Rust backend for artist/page and releases/grid endpoints
Add PageArtistResponse and ReleasesGridResponse types with all supporting structs for the /artist/page and /artist/getReleasesGrid Qobuz API endpoints. Add client methods and Tauri commands.
This commit is contained in:
1 parent
ee7ea4f164
commit
b6202ebb66
5 files changed
+298
-1
No files matched your search
@@ -1120,6 +1120,70 @@ impl QobuzClient {
|
||||
Err(ApiError::ApiResponse(format!("Failed to remove favorite: {}", response.status())))
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Artist Page Endpoints ============
|
||||
|
||||
/// Get artist page (aggregated: bio, top tracks, releases, similar, playlists)
|
||||
pub async fn get_artist_page(
|
||||
&self,
|
||||
artist_id: u64,
|
||||
sort: Option<&str>,
|
||||
) -> Result<PageArtistResponse> {
|
||||
let url = endpoints::build_url(paths::ARTIST_PAGE);
|
||||
let mut query = vec![
|
||||
("artist_id", artist_id.to_string()),
|
||||
];
|
||||
if let Some(s) = sort {
|
||||
query.push(("sort", s.to_string()));
|
||||
}
|
||||
|
||||
log::debug!("[API] get_artist_page({}) sort={:?}", artist_id, sort);
|
||||
let response: serde_json::Value = self
|
||||
.http
|
||||
.get(&url)
|
||||
.headers(self.api_headers().await?)
|
||||
.query(&query)
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
Ok(serde_json::from_value(response)?)
|
||||
}
|
||||
|
||||
/// Get artist releases grid (paginated by release_type)
|
||||
pub async fn get_releases_grid(
|
||||
&self,
|
||||
artist_id: u64,
|
||||
release_type: &str,
|
||||
limit: u32,
|
||||
offset: u32,
|
||||
sort: Option<&str>,
|
||||
) -> Result<ReleasesGridResponse> {
|
||||
let url = endpoints::build_url(paths::ARTIST_RELEASES_GRID);
|
||||
let mut query = vec![
|
||||
("artist_id", artist_id.to_string()),
|
||||
("release_type", release_type.to_string()),
|
||||
("limit", limit.to_string()),
|
||||
("offset", offset.to_string()),
|
||||
];
|
||||
if let Some(s) = sort {
|
||||
query.push(("sort", s.to_string()));
|
||||
}
|
||||
|
||||
log::debug!("[API] get_releases_grid({}) type={} limit={} offset={}", artist_id, release_type, limit, offset);
|
||||
let response: serde_json::Value = self
|
||||
.http
|
||||
.get(&url)
|
||||
.headers(self.api_headers().await?)
|
||||
.query(&query)
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
Ok(serde_json::from_value(response)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for QobuzClient {
|
||||
|
||||
@@ -21,6 +21,9 @@ pub mod paths {
|
||||
pub const ARTIST_GET: &str = "/artist/get";
|
||||
pub const ARTIST_SEARCH: &str = "/artist/search";
|
||||
pub const ARTIST_GET_SIMILAR: &str = "/artist/getSimilarArtists";
|
||||
pub const ARTIST_PAGE: &str = "/artist/page";
|
||||
pub const ARTIST_RELEASES_GRID: &str = "/artist/getReleasesGrid";
|
||||
pub const ARTIST_RELEASES_LIST: &str = "/artist/getReleasesList";
|
||||
|
||||
// Playlist
|
||||
pub const PLAYLIST_GET: &str = "/playlist/get";
|
||||
|
||||
@@ -470,3 +470,187 @@ pub struct DiscoverAudioInfo {
|
||||
pub maximum_bit_depth: Option<u32>,
|
||||
pub maximum_channel_count: Option<u32>,
|
||||
}
|
||||
|
||||
// ============ Artist Page Types (/artist/page) ============
|
||||
|
||||
/// Top-level response from /artist/page
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistResponse {
|
||||
pub id: u64,
|
||||
pub name: PageArtistName,
|
||||
pub artist_category: Option<String>,
|
||||
pub biography: Option<PageArtistBiography>,
|
||||
pub images: Option<PageArtistImages>,
|
||||
pub similar_artists: Option<PageArtistSimilar>,
|
||||
pub top_tracks: Option<Vec<PageArtistTrack>>,
|
||||
pub last_release: Option<serde_json::Value>,
|
||||
pub releases: Option<Vec<PageArtistReleaseGroup>>,
|
||||
pub tracks_appears_on: Option<Vec<PageArtistTrack>>,
|
||||
pub playlists: Option<PageArtistPlaylists>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistName {
|
||||
pub display: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistBiography {
|
||||
pub content: Option<String>,
|
||||
pub source: Option<serde_json::Value>,
|
||||
pub language: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistImages {
|
||||
pub portrait: Option<PageArtistPortrait>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistPortrait {
|
||||
pub hash: String,
|
||||
pub format: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistSimilar {
|
||||
pub has_more: bool,
|
||||
pub items: Vec<PageArtistSimilarItem>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistSimilarItem {
|
||||
pub id: u64,
|
||||
pub name: PageArtistName,
|
||||
pub images: Option<PageArtistImages>,
|
||||
}
|
||||
|
||||
/// A group of releases by type (e.g., "album", "ep", "live")
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistReleaseGroup {
|
||||
#[serde(rename = "type")]
|
||||
pub release_type: String,
|
||||
pub has_more: bool,
|
||||
pub items: Vec<PageArtistRelease>,
|
||||
}
|
||||
|
||||
/// A release item (album/ep/live/etc) from /artist/page or /artist/getReleasesGrid
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistRelease {
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
pub version: Option<String>,
|
||||
pub tracks_count: Option<u32>,
|
||||
pub artist: Option<PageArtistReleaseArtist>,
|
||||
pub artists: Option<Vec<PageArtistReleaseContributor>>,
|
||||
pub image: Option<ImageSet>,
|
||||
pub label: Option<Label>,
|
||||
pub genre: Option<Genre>,
|
||||
pub release_type: Option<String>,
|
||||
pub release_tags: Option<Vec<String>>,
|
||||
pub duration: Option<u32>,
|
||||
pub dates: Option<DiscoverAlbumDates>,
|
||||
pub parental_warning: Option<bool>,
|
||||
pub audio_info: Option<DiscoverAudioInfo>,
|
||||
pub rights: Option<PageArtistRights>,
|
||||
pub awards: Option<Vec<PageArtistAward>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistReleaseArtist {
|
||||
pub id: u64,
|
||||
pub name: PageArtistName,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistReleaseContributor {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub roles: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistRights {
|
||||
pub streamable: Option<bool>,
|
||||
pub hires_streamable: Option<bool>,
|
||||
pub hires_purchasable: Option<bool>,
|
||||
pub purchasable: Option<bool>,
|
||||
pub downloadable: Option<bool>,
|
||||
pub previewable: Option<bool>,
|
||||
pub sampleable: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistAward {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub awarded_at: Option<String>,
|
||||
}
|
||||
|
||||
/// Track from /artist/page (top_tracks or tracks_appears_on)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistTrack {
|
||||
pub id: u64,
|
||||
pub title: String,
|
||||
pub version: Option<String>,
|
||||
pub duration: Option<u32>,
|
||||
pub isrc: Option<String>,
|
||||
pub parental_warning: Option<bool>,
|
||||
pub artist: Option<PageArtistReleaseArtist>,
|
||||
pub composer: Option<serde_json::Value>,
|
||||
pub audio_info: Option<DiscoverAudioInfo>,
|
||||
pub rights: Option<PageArtistRights>,
|
||||
pub physical_support: Option<PageArtistPhysicalSupport>,
|
||||
pub album: Option<PageArtistTrackAlbum>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistPhysicalSupport {
|
||||
pub media_number: Option<u32>,
|
||||
pub track_number: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistTrackAlbum {
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
pub version: Option<String>,
|
||||
pub image: Option<ImageSet>,
|
||||
pub label: Option<Label>,
|
||||
pub genre: Option<Genre>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistPlaylists {
|
||||
pub has_more: bool,
|
||||
pub items: Vec<PageArtistPlaylist>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistPlaylist {
|
||||
pub id: u64,
|
||||
pub title: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub owner: Option<PageArtistPlaylistOwner>,
|
||||
pub tracks_count: Option<u32>,
|
||||
pub duration: Option<u32>,
|
||||
pub images: Option<PageArtistPlaylistImages>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistPlaylistOwner {
|
||||
pub id: u64,
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistPlaylistImages {
|
||||
pub rectangle: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
/// Response from /artist/getReleasesGrid
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ReleasesGridResponse {
|
||||
pub has_more: bool,
|
||||
pub items: Vec<PageArtistRelease>,
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use tauri::State;
|
||||
|
||||
use crate::api::{endpoints, endpoints::paths, Album, Artist, ArtistAlbums, DiscoverResponse, DiscoverPlaylistsResponse, LabelDetail, Playlist, SearchResultsPage, Track, TracksContainer};
|
||||
use crate::api::{endpoints, endpoints::paths, Album, Artist, ArtistAlbums, DiscoverResponse, DiscoverPlaylistsResponse, LabelDetail, PageArtistResponse, Playlist, ReleasesGridResponse, SearchResultsPage, Track, TracksContainer};
|
||||
use crate::api_cache::ApiCacheState;
|
||||
use crate::artist_blacklist::BlacklistState;
|
||||
use crate::AppState;
|
||||
@@ -692,3 +692,47 @@ pub async fn get_discover_playlists(
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Get artist page (aggregated: bio, top tracks, releases, similar, playlists)
|
||||
#[tauri::command]
|
||||
pub async fn get_artist_page(
|
||||
artist_id: u64,
|
||||
sort: Option<String>,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<PageArtistResponse, String> {
|
||||
log::debug!("Command: get_artist_page {} sort={:?}", artist_id, sort);
|
||||
|
||||
let client = state.client.lock().await;
|
||||
client
|
||||
.get_artist_page(artist_id, sort.as_deref())
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Get artist releases grid (paginated by release_type)
|
||||
#[tauri::command]
|
||||
pub async fn get_releases_grid(
|
||||
artist_id: u64,
|
||||
release_type: String,
|
||||
limit: Option<u32>,
|
||||
offset: Option<u32>,
|
||||
sort: Option<String>,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ReleasesGridResponse, String> {
|
||||
log::debug!(
|
||||
"Command: get_releases_grid {} type={} limit={:?} offset={:?}",
|
||||
artist_id, release_type, limit, offset
|
||||
);
|
||||
|
||||
let client = state.client.lock().await;
|
||||
client
|
||||
.get_releases_grid(
|
||||
artist_id,
|
||||
&release_type,
|
||||
limit.unwrap_or(25),
|
||||
offset.unwrap_or(0),
|
||||
sort.as_deref(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
@@ -460,6 +460,8 @@ pub fn run() {
|
||||
commands::get_artist_tracks,
|
||||
commands::get_artist_albums,
|
||||
commands::get_similar_artists,
|
||||
commands::get_artist_page,
|
||||
commands::get_releases_grid,
|
||||
commands::get_label,
|
||||
// Playback commands
|
||||
commands::play_track,
|
||||
|
||||
Reference in new issue
Block a user