From b43a8ac4d0b005c59986809840da6569cfc49f8b Mon Sep 17 00:00:00 2001 From: Erica Z Date: Fri, 1 Nov 2024 09:43:55 +0100 Subject: [PATCH] test getRandomSongs endpoint --- src/main.rs | 1 + src/subsonic.rs | 11 ++++++++++- src/subsonic/schema.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ef5ed99..4ccdf9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,6 +62,7 @@ fn main() -> glib::ExitCode { ) .unwrap(); client.ping().await.unwrap(); + println!("{:#?}", client.get_random_songs(10).await.unwrap()); } }); diff --git a/src/subsonic.rs b/src/subsonic.rs index f62cb19..15715d2 100644 --- a/src/subsonic.rs +++ b/src/subsonic.rs @@ -92,7 +92,7 @@ impl Client { async fn get( &self, path: &[&str], - query: &[&str], + query: &[(&str, &str)], ) -> Result { let mut url = self.base_url.clone(); url.path_segments_mut() @@ -115,4 +115,13 @@ impl Client { pub async fn ping(&self) -> Result<(), Error> { self.get(&["rest", "ping"], &[]).await } + + pub async fn get_random_songs(&self, size: u32) -> Result, Error> { + self.get::( + &["rest", "getRandomSongs"], + &[("size", &size.to_string())], + ) + .await + .map(|response| response.random_songs.song) + } } diff --git a/src/subsonic/schema.rs b/src/subsonic/schema.rs index e3537da..cf9a262 100644 --- a/src/subsonic/schema.rs +++ b/src/subsonic/schema.rs @@ -23,3 +23,30 @@ pub struct Error { pub code: u32, pub message: String, } + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RandomSongsOuter { + pub random_songs: RandomSongs, +} + +#[derive(Debug, Deserialize)] +pub struct RandomSongs { + pub song: Vec, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Child { + pub id: String, + pub title: String, + pub album: String, + pub artist: String, + pub track: u32, + pub year: u32, + pub starred: Option<()>, + pub duration: u64, + pub play_count: Option, + pub genre: Option, + pub cover_art: String, +}