Wip
This commit is contained in:
parent
96bae9a045
commit
9c91f660d8
5 changed files with 277 additions and 34 deletions
140
src/main.rs
140
src/main.rs
|
@ -1,6 +1,8 @@
|
|||
extern crate libnotify;
|
||||
extern crate mpd;
|
||||
|
||||
use std::time::Duration;
|
||||
use std::{io, usize};
|
||||
|
||||
use mpd::{Client, Query, Song, Term};
|
||||
|
||||
|
@ -16,6 +18,7 @@ struct Cli {
|
|||
|
||||
#[arg(short, long, global = true)]
|
||||
verbose: bool,
|
||||
///hostname where MPD listens at
|
||||
#[arg(short = 'H', long, global = true)]
|
||||
host: Option<String>,
|
||||
}
|
||||
|
@ -46,9 +49,26 @@ enum Commands {
|
|||
///Only return the first n results
|
||||
#[arg(short, long)]
|
||||
max: Option<u32>,
|
||||
#[arg(short, long)]
|
||||
append: bool,
|
||||
#[arg(short, long)]
|
||||
insert: Option<u32>,
|
||||
},
|
||||
///List items in the current queueueu
|
||||
/// Query database differently
|
||||
Find {
|
||||
///Search query
|
||||
#[arg(trailing_var_arg = true)]
|
||||
query: Vec<String>,
|
||||
///Only return the first n results
|
||||
#[arg(short, long)]
|
||||
max: Option<u32>,
|
||||
},
|
||||
/// List items in the current queueueu
|
||||
List {},
|
||||
Add {
|
||||
#[arg(short, long)]
|
||||
position: Option<u32>,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -59,7 +79,14 @@ fn main() {
|
|||
None => String::from("localhost:6600"),
|
||||
};
|
||||
|
||||
let mut conn = Client::connect(host).unwrap();
|
||||
// let mut conn = Client::connect(host).unwrap();
|
||||
|
||||
let mut conn = Client::connect(host).expect("Things");
|
||||
|
||||
// let mut conn = match Client::connect(host) {
|
||||
// Ok(conn) => conn,
|
||||
// Err(error) => panic!("yo fucked up: {}", error.to_string()),
|
||||
// };
|
||||
|
||||
if let Some(cmd) = &cli.command {
|
||||
match cmd {
|
||||
|
@ -73,25 +100,47 @@ fn main() {
|
|||
|
||||
Commands::Stop {} => conn.stop().unwrap(),
|
||||
|
||||
Commands::Toggle {} => conn.toggle_pause().unwrap(),
|
||||
Commands::Toggle {} => {
|
||||
println!(
|
||||
"{}",
|
||||
match conn.status().unwrap().state {
|
||||
mpd::State::Pause => "Resuming track...",
|
||||
mpd::State::Play => "Pausing track...",
|
||||
mpd::State::Stop => "Track stopped",
|
||||
}
|
||||
);
|
||||
conn.toggle_pause().unwrap();
|
||||
let status = get_status(conn, cli.verbose);
|
||||
println!("{status}");
|
||||
}
|
||||
|
||||
Commands::Next {} => conn.next().unwrap(),
|
||||
|
||||
Commands::Prev {} => conn.prev().unwrap(),
|
||||
|
||||
Commands::List {} => print_songs(conn.queue().unwrap()),
|
||||
|
||||
// Commands::List {} => {
|
||||
// conn.insert(first_song, usize::try_from(1).unwrap());
|
||||
// println!("{:?}", conn.queue().unwrap().first());
|
||||
// }
|
||||
Commands::Update {} => {
|
||||
let thing = conn.update().unwrap();
|
||||
println!("{}", thing)
|
||||
println!("{thing}")
|
||||
}
|
||||
|
||||
Commands::Current {} => {
|
||||
println!("{}", format_song(conn.currentsong().unwrap().unwrap()))
|
||||
let status = get_status(conn, cli.verbose);
|
||||
println!("{status}");
|
||||
}
|
||||
|
||||
Commands::Search { query, max } => {
|
||||
Commands::Search {
|
||||
query,
|
||||
max,
|
||||
append,
|
||||
insert,
|
||||
} => {
|
||||
let mut result: Vec<String> = vec![];
|
||||
let mut songs: Vec<Song> = vec![];
|
||||
let query = query.join(" ");
|
||||
// I want to return all results by default
|
||||
let window = (
|
||||
|
@ -102,11 +151,43 @@ fn main() {
|
|||
conn.stats().unwrap().songs
|
||||
},
|
||||
);
|
||||
conn.search(&Query::new().and(Term::Any, query), window)
|
||||
if *append {
|
||||
let queue_length = conn.status().unwrap().queue_len;
|
||||
let _song = conn
|
||||
.search(&Query::new().and(Term::Any, query), window)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|x| songs.push(x.clone()));
|
||||
conn.insert(
|
||||
songs.first().unwrap(),
|
||||
usize::try_from(queue_length).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
} else {
|
||||
conn.search(&Query::new().and(Term::Any, query), window)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.for_each(|x| result.push(x.file.clone()));
|
||||
result.iter().for_each(|x| println!("{x}"))
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Find { query, max } => {
|
||||
let mut result: Vec<String> = vec![];
|
||||
let query = query.join(" ");
|
||||
let window = (
|
||||
0,
|
||||
if let Some(n) = max {
|
||||
*n
|
||||
} else {
|
||||
conn.stats().unwrap().songs
|
||||
},
|
||||
);
|
||||
conn.find(&Query::new().and(Term::Any, query), window)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.for_each(|x| result.push(x.file.clone()));
|
||||
result.iter().for_each(|x| println!("{}", x))
|
||||
result.iter().for_each(|x| println!("{x}"))
|
||||
}
|
||||
|
||||
Commands::Crossfade { seconds } => {
|
||||
|
@ -120,12 +201,36 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Add { position } => {
|
||||
// insert_or_append(conn, *position);
|
||||
println!("{:?}", position);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("{}", get_status(conn, cli.verbose));
|
||||
let status = get_status(conn, cli.verbose);
|
||||
println!("{}", status);
|
||||
// println!("{:?}", conn.status().unwrap());
|
||||
|
||||
libnotify::init("noise").unwrap();
|
||||
let n = libnotify::Notification::new("Noise", None, None);
|
||||
n.show().unwrap();
|
||||
|
||||
libnotify::uninit();
|
||||
}
|
||||
}
|
||||
|
||||
fn stdin_reader() -> String {
|
||||
"fiets".to_string()
|
||||
}
|
||||
|
||||
// fn insert_or_append(mut client: Client, position: Option<u32>) {
|
||||
// if let Some(pos) = position {
|
||||
// client.insert(usize::try_from(1).unwrap(), usize::try_from(pos).unwrap());
|
||||
// // let position = usize::try_from(position.unwrap()).unwrap();
|
||||
// }
|
||||
// }
|
||||
|
||||
fn print_songs(songs: Vec<Song>) -> () {
|
||||
songs
|
||||
.iter()
|
||||
|
@ -152,7 +257,7 @@ fn get_status(mut client: Client, verbose: bool) -> String {
|
|||
Some((stamp, total)) => {
|
||||
let stamp = to_mins_string(stamp);
|
||||
let total = to_mins_string(total);
|
||||
format!("{}/{}", stamp, total)
|
||||
format!("{stamp}/{total}")
|
||||
}
|
||||
None => "".to_string(),
|
||||
};
|
||||
|
@ -175,9 +280,14 @@ fn get_status(mut client: Client, verbose: bool) -> String {
|
|||
));
|
||||
|
||||
output.push(format!(
|
||||
"[{:?}] {}",
|
||||
client.status().unwrap().state,
|
||||
duration
|
||||
"[{status}] {duration}",
|
||||
status = {
|
||||
match client.status().unwrap().state {
|
||||
mpd::State::Stop => "stopped",
|
||||
mpd::State::Pause => "paused",
|
||||
mpd::State::Play => "playing",
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -190,5 +300,5 @@ fn to_mins_string(dur: Duration) -> String {
|
|||
let minutes = seconds / 60;
|
||||
let rem_seconds = seconds % 60;
|
||||
|
||||
format!("{:02}:{:02}", minutes, rem_seconds)
|
||||
format!("{minutes:02}:{rem_seconds:02}")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue