Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
eddf2231e9 | |||
c9ac64d504 | |||
|
5556ea70df |
5 changed files with 66 additions and 45 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -268,7 +268,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "noise"
|
name = "noise"
|
||||||
version = "0.1.7"
|
version = "0.1.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"clap_complete",
|
"clap_complete",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "noise"
|
name = "noise"
|
||||||
version = "0.1.7"
|
version = "0.1.9"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["Nox Sluijtman"]
|
authors = ["Nox Sluijtman"]
|
||||||
|
|
||||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -5,7 +5,7 @@ use noise::{commands::Noise, parser::*};
|
||||||
|
|
||||||
use clap::{Command, CommandFactory, Parser};
|
use clap::{Command, CommandFactory, Parser};
|
||||||
use clap_complete::{generate, Generator};
|
use clap_complete::{generate, Generator};
|
||||||
use mpd::Client;
|
use mpd::{error::Error, Client};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
|
fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
|
||||||
|
@ -17,23 +17,26 @@ fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), Error> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
if let Some(completions) = cli.completions {
|
if let Some(completions) = cli.completions {
|
||||||
let mut cmd = Cli::command();
|
let mut cmd = Cli::command();
|
||||||
eprintln!("Generatig completion file for {completions:?}...");
|
eprintln!("Generatig completion file for {completions:?}...");
|
||||||
print_completions(completions, &mut cmd);
|
print_completions(completions, &mut cmd);
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let host = cli.host.unwrap_or("localhost:6600".into());
|
let host = cli.host.unwrap_or("localhost:6600".into());
|
||||||
|
|
||||||
let mut conn = Client::connect(host).expect("Connection failed");
|
let mut conn = match Client::connect(host) {
|
||||||
|
Ok(client) => client,
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(cmd) = &cli.command {
|
if let Some(cmd) = &cli.command {
|
||||||
match cmd {
|
match cmd {
|
||||||
Commands::Play { track } => conn.noise_play(*track),
|
Commands::Play { track } => Noise::play(&mut conn, *track),
|
||||||
Commands::Stop => conn.stop().unwrap(),
|
Commands::Stop => conn.stop().unwrap(),
|
||||||
Commands::Toggle => conn.toggle(),
|
Commands::Toggle => conn.toggle(),
|
||||||
Commands::Next => conn.next().unwrap(),
|
Commands::Next => conn.next().unwrap(),
|
||||||
|
@ -41,9 +44,9 @@ fn main() {
|
||||||
Commands::List { file } => conn.list_queue(*file, cli.verbose),
|
Commands::List { file } => conn.list_queue(*file, cli.verbose),
|
||||||
Commands::Current => (),
|
Commands::Current => (),
|
||||||
Commands::Clear => conn.clear().unwrap(),
|
Commands::Clear => conn.clear().unwrap(),
|
||||||
Commands::Search { query, max } => conn.noise_search(query, *max),
|
Commands::Search { query, max } => Noise::search(&mut conn, query, *max),
|
||||||
Commands::Find { query, max, append } => conn.noise_find(query, *max, *append),
|
Commands::Find { query, max, append } => Noise::find(&mut conn, query, *max, *append),
|
||||||
Commands::Crossfade { seconds } => conn.noise_crossfade(*seconds),
|
Commands::Crossfade { seconds } => Noise::crossfade(&mut conn, *seconds),
|
||||||
Commands::Shuffle => conn.shuf(),
|
Commands::Shuffle => conn.shuf(),
|
||||||
Commands::Repeat => conn.toggle_repeat(),
|
Commands::Repeat => conn.toggle_repeat(),
|
||||||
Commands::Random => conn.toggle_random(),
|
Commands::Random => conn.toggle_random(),
|
||||||
|
@ -60,10 +63,18 @@ fn main() {
|
||||||
| Commands::Search { .. }
|
| Commands::Search { .. }
|
||||||
| Commands::Find { .. }
|
| Commands::Find { .. }
|
||||||
| Commands::Crossfade { .. }
|
| Commands::Crossfade { .. }
|
||||||
|
| Commands::Volume { .. }
|
||||||
| Commands::Shuffle = cmd
|
| Commands::Shuffle = cmd
|
||||||
{
|
{
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let _things: Vec<String> = conn
|
||||||
|
.queue()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.place.unwrap().pos.to_string())
|
||||||
|
.collect();
|
||||||
println!("{}", conn.get_status(cli.verbose));
|
println!("{}", conn.get_status(cli.verbose));
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,13 @@ extern crate mpd;
|
||||||
|
|
||||||
use libnotify::Notification;
|
use libnotify::Notification;
|
||||||
use mpd::{Client, Query, Song, State, Term};
|
use mpd::{Client, Query, Song, State, Term};
|
||||||
use std::time::Duration;
|
use std::{env, time::Duration};
|
||||||
|
|
||||||
pub trait Noise {
|
pub trait Noise {
|
||||||
fn noise_find(&mut self, query: &Vec<String>, max: Option<u32>, append: bool);
|
fn find(&mut self, query: &Vec<String>, max: Option<u32>, append: bool);
|
||||||
fn noise_search(&mut self, query: &Vec<String>, max: Option<u32>);
|
fn search(&mut self, query: &Vec<String>, max: Option<u32>);
|
||||||
fn noise_crossfade(&mut self, seconds: Option<i64>);
|
fn crossfade(&mut self, seconds: Option<i64>);
|
||||||
fn noise_play(&mut self, track: Option<u32>);
|
fn play(&mut self, track: Option<u32>);
|
||||||
fn toggle(&mut self);
|
fn toggle(&mut self);
|
||||||
fn munch(&mut self);
|
fn munch(&mut self);
|
||||||
fn length(&mut self);
|
fn length(&mut self);
|
||||||
|
@ -24,7 +24,7 @@ pub trait Noise {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Noise for Client {
|
impl Noise for Client {
|
||||||
fn noise_find(&mut self, query: &Vec<String>, max: Option<u32>, append: bool) {
|
fn find(&mut self, query: &Vec<String>, max: Option<u32>, append: bool) {
|
||||||
let query = query.join(" ");
|
let query = query.join(" ");
|
||||||
let max = max.unwrap_or(self.stats().unwrap().songs);
|
let max = max.unwrap_or(self.stats().unwrap().songs);
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ impl Noise for Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn noise_search(&mut self, query: &Vec<String>, max: Option<u32>) {
|
fn search(&mut self, query: &Vec<String>, max: Option<u32>) {
|
||||||
let query = query.join(" ");
|
let query = query.join(" ");
|
||||||
let max = max.unwrap_or(self.stats().unwrap().songs);
|
let max = max.unwrap_or(self.stats().unwrap().songs);
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ impl Noise for Client {
|
||||||
.for_each(|x| println!("{}", x.file));
|
.for_each(|x| println!("{}", x.file));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn noise_crossfade(&mut self, seconds: Option<i64>) {
|
fn crossfade(&mut self, seconds: Option<i64>) {
|
||||||
if let Some(seconds) = seconds {
|
if let Some(seconds) = seconds {
|
||||||
self.crossfade(seconds).unwrap();
|
self.crossfade(seconds).unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,7 +62,7 @@ impl Noise for Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn noise_play(&mut self, track: Option<u32>) {
|
fn play(&mut self, track: Option<u32>) {
|
||||||
if let Some(i) = track {
|
if let Some(i) = track {
|
||||||
self.switch(i).unwrap();
|
self.switch(i).unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
@ -79,9 +79,8 @@ impl Noise for Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn munch(&mut self) {
|
fn munch(&mut self) {
|
||||||
// let current_song = self.currentsong().unwrap().unwrap().place.unwrap();
|
let current_song = self.currentsong().unwrap().unwrap().place.unwrap();
|
||||||
// self.delete(current_song).unwrap();
|
self.delete(current_song.pos).unwrap();
|
||||||
todo!("Not net implemented")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn length(&mut self) {
|
fn length(&mut self) {
|
||||||
|
@ -175,12 +174,23 @@ impl Noise for Client {
|
||||||
State::Play => "playing",
|
State::Play => "playing",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn to_mins_string(dur: Duration) -> String {
|
||||||
|
let seconds = dur.as_secs();
|
||||||
|
|
||||||
|
let minutes = seconds / 60;
|
||||||
|
let rem_seconds = seconds % 60;
|
||||||
|
|
||||||
|
format!("{minutes:02}:{rem_seconds:02}")
|
||||||
|
}
|
||||||
|
|
||||||
let duration = status.time.map_or("".into(), |(stamp, total)| {
|
let duration = status.time.map_or("".into(), |(stamp, total)| {
|
||||||
let stamp = to_mins_string(stamp);
|
let stamp = to_mins_string(stamp);
|
||||||
let total = to_mins_string(total);
|
let total = to_mins_string(total);
|
||||||
format!("{stamp}/{total}")
|
format!("{stamp}/{total}")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// let pos_in_queue = format!("{current_pos}/{queue_lenth}");
|
||||||
|
|
||||||
output.push(format!("[{state}] {duration}"));
|
output.push(format!("[{state}] {duration}"));
|
||||||
|
|
||||||
output.join("\n")
|
output.join("\n")
|
||||||
|
@ -198,16 +208,16 @@ fn format_song(song: Song) -> String {
|
||||||
// fn get_status(client: &mut Client, verbose: bool) -> String {}
|
// fn get_status(client: &mut Client, verbose: bool) -> String {}
|
||||||
|
|
||||||
fn send_notification(body: &str) {
|
fn send_notification(body: &str) {
|
||||||
libnotify::init("noise").unwrap();
|
let key = "XDG_SESSION_TYPE";
|
||||||
let notify = Notification::new("Noise", Some(body), None);
|
match env::var(key) {
|
||||||
notify.show().unwrap();
|
Ok(key) => {
|
||||||
}
|
if key != "tty" {
|
||||||
|
libnotify::init("noise").unwrap();
|
||||||
fn to_mins_string(dur: Duration) -> String {
|
let notify = Notification::new("Noise", Some(body), None);
|
||||||
let seconds = dur.as_secs();
|
notify.show().unwrap();
|
||||||
|
libnotify::uninit();
|
||||||
let minutes = seconds / 60;
|
}
|
||||||
let rem_seconds = seconds % 60;
|
}
|
||||||
|
Err(_) => return,
|
||||||
format!("{minutes:02}:{rem_seconds:02}")
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,13 @@ pub struct Cli {
|
||||||
|
|
||||||
#[derive(Subcommand, Debug, PartialEq)]
|
#[derive(Subcommand, Debug, PartialEq)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
|
/// Stops playing
|
||||||
|
Stop,
|
||||||
|
/// Play queueueu
|
||||||
|
Play {
|
||||||
|
#[arg(value_hint = ValueHint::CommandString)]
|
||||||
|
track: Option<u32>,
|
||||||
|
},
|
||||||
/// Toggle MPD playback
|
/// Toggle MPD playback
|
||||||
#[command(visible_alias = "t")]
|
#[command(visible_alias = "t")]
|
||||||
Toggle,
|
Toggle,
|
||||||
|
@ -37,14 +44,6 @@ pub enum Commands {
|
||||||
Next,
|
Next,
|
||||||
/// Revert to the previous track
|
/// Revert to the previous track
|
||||||
Prev,
|
Prev,
|
||||||
/// Stops playing
|
|
||||||
Stop,
|
|
||||||
/// Play queueueu
|
|
||||||
#[command(visible_alias = "start")]
|
|
||||||
Play {
|
|
||||||
#[arg(value_hint = ValueHint::Other)]
|
|
||||||
track: Option<u32>,
|
|
||||||
},
|
|
||||||
/// Set or get crossfade
|
/// Set or get crossfade
|
||||||
#[command(visible_alias = "fade")]
|
#[command(visible_alias = "fade")]
|
||||||
Crossfade {
|
Crossfade {
|
||||||
|
@ -53,8 +52,6 @@ pub enum Commands {
|
||||||
},
|
},
|
||||||
// ///Update still needs some work
|
// ///Update still needs some work
|
||||||
// Update,
|
// Update,
|
||||||
/// Return currently playing song
|
|
||||||
Current,
|
|
||||||
/// Clear current queueueu
|
/// Clear current queueueu
|
||||||
Clear,
|
Clear,
|
||||||
/// Query database
|
/// Query database
|
||||||
|
@ -71,6 +68,8 @@ pub enum Commands {
|
||||||
// #[arg(short, long)]
|
// #[arg(short, long)]
|
||||||
// insert: Option<u32>,
|
// insert: Option<u32>,
|
||||||
},
|
},
|
||||||
|
/// Return currently playing song
|
||||||
|
Current,
|
||||||
/// Query database autistically
|
/// Query database autistically
|
||||||
#[command(visible_alias = "fd")]
|
#[command(visible_alias = "fd")]
|
||||||
Find {
|
Find {
|
||||||
|
@ -110,6 +109,7 @@ pub enum Commands {
|
||||||
#[arg(value_hint = ValueHint::Other)]
|
#[arg(value_hint = ValueHint::Other)]
|
||||||
percentage: Option<i8>,
|
percentage: Option<i8>,
|
||||||
},
|
},
|
||||||
|
/// Remove the current track
|
||||||
Munch,
|
Munch,
|
||||||
Length,
|
Length,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue