added searching and standard messages
This commit is contained in:
parent
b4b1ac8d62
commit
2561b3fde1
2 changed files with 53 additions and 7 deletions
29
src/main.rs
29
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<String>,
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<String>,
|
||||
pub title: Option<String>,
|
||||
|
@ -51,6 +73,11 @@ impl PartialTag {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ServerResponse {
|
||||
pub search_results: Vec<ItemTag>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue