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 clap::{Parser, ValueEnum};
|
||||||
use message_types::UIRequest;
|
use message_types::{PartialTag, UIRequest};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use tungstenite::{connect, Message};
|
use tungstenite::{connect, Message};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -37,7 +37,7 @@ struct CliArgs {
|
||||||
short,
|
short,
|
||||||
long,
|
long,
|
||||||
required_if_eq("action", "search"),
|
required_if_eq("action", "search"),
|
||||||
value_parser(["title", "artist", "album", "album_artist"])
|
value_parser(["title", "artist", "album"])
|
||||||
)]
|
)]
|
||||||
search_field: Option<String>,
|
search_field: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,30 @@ fn main() {
|
||||||
let message_string = match cli.action.unwrap() {
|
let message_string = match cli.action.unwrap() {
|
||||||
SousaCommands::Play => serde_json::to_string(&UIRequest::Play).unwrap(),
|
SousaCommands::Play => serde_json::to_string(&UIRequest::Play).unwrap(),
|
||||||
SousaCommands::Pause => serde_json::to_string(&UIRequest::Pause).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();
|
socket.write_message(Message::Text(message_string)).unwrap();
|
||||||
//let msg = socket.read_message().expect("Error reading message");
|
let msg = socket.read_message().expect("Error reading message");
|
||||||
//println!("Received: {}", msg);
|
println!("Received: {}", msg);
|
||||||
socket.close(None).unwrap();
|
socket.close(None).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,28 @@
|
||||||
use serde::{Deserialize, Serialize};
|
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 struct PartialTag {
|
||||||
pub path: Option<String>,
|
pub path: Option<String>,
|
||||||
pub title: 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)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub enum SkipDirection {
|
pub enum SkipDirection {
|
||||||
Forward,
|
Forward,
|
||||||
|
@ -62,7 +89,7 @@ pub enum UIRequest {
|
||||||
Play,
|
Play,
|
||||||
Pause,
|
Pause,
|
||||||
Skip(SkipDirection),
|
Skip(SkipDirection),
|
||||||
GetList(String),
|
Search(PartialTag),
|
||||||
SwitchTo(PartialTag),
|
SwitchTo(PartialTag),
|
||||||
GetStatus,
|
GetStatus,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue