diff --git a/src/main.rs b/src/main.rs index 2194f5a..6525da0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use clap::{Parser, ValueEnum}; -use message_types::UIRequest; +use message_types::{PartialTag, UIRequest}; use serde_json; use tungstenite::{connect, Message}; use url::Url; @@ -37,7 +37,7 @@ struct CliArgs { short, long, required_if_eq("action", "search"), - value_parser(["title", "artist", "album", "album_artist"]) + value_parser(["title", "artist", "album"]) )] search_field: Option, } @@ -54,11 +54,30 @@ fn main() { let message_string = match cli.action.unwrap() { SousaCommands::Play => serde_json::to_string(&UIRequest::Play).unwrap(), SousaCommands::Pause => serde_json::to_string(&UIRequest::Pause).unwrap(), - SousaCommands::Search => String::new(), + SousaCommands::Search => { + let request: UIRequest = match cli.search_field.unwrap().to_lowercase().as_str() { + "title" => UIRequest::Search(PartialTag { + title: cli.search_arg, + ..PartialTag::default() + }), + "artist" => UIRequest::Search(PartialTag { + artist: cli.search_arg, + ..PartialTag::default() + }), + "album" => UIRequest::Search(PartialTag { + album: cli.search_arg, + ..PartialTag::default() + }), + _ => panic!( + "Unknown search type! Expected values are 'title', 'artist', and 'album'" + ), + }; + serde_json::to_string(&request).unwrap() + } }; socket.write_message(Message::Text(message_string)).unwrap(); - //let msg = socket.read_message().expect("Error reading message"); - //println!("Received: {}", msg); + let msg = socket.read_message().expect("Error reading message"); + println!("Received: {}", msg); socket.close(None).unwrap(); } diff --git a/src/message_types.rs b/src/message_types.rs index 6f92edd..d68cb8c 100644 --- a/src/message_types.rs +++ b/src/message_types.rs @@ -1,6 +1,28 @@ use serde::{Deserialize, Serialize}; -#[derive(Deserialize, Serialize)] +/// A struct that defines all the music tags supported by Sousa +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct ItemTag { + pub path: String, + pub title: String, + pub artist: String, + pub album: String, + pub album_artist: String, +} + +impl Default for ItemTag { + fn default() -> Self { + ItemTag { + path: String::new(), + title: String::new(), + artist: String::new(), + album: String::new(), + album_artist: String::new(), + } + } +} + +#[derive(Deserialize, Serialize, Debug)] pub struct PartialTag { pub path: Option, pub title: Option, @@ -51,6 +73,11 @@ impl PartialTag { } } +#[derive(Serialize, Deserialize)] +pub struct ServerResponse { + pub search_results: Vec, +} + #[derive(Serialize, Deserialize)] pub enum SkipDirection { Forward, @@ -62,7 +89,7 @@ pub enum UIRequest { Play, Pause, Skip(SkipDirection), - GetList(String), + Search(PartialTag), SwitchTo(PartialTag), GetStatus, }