Added quite a few of the features I want
Some checks are pending
Build legacy Nix package on Ubuntu / build (push) Waiting to run
Some checks are pending
Build legacy Nix package on Ubuntu / build (push) Waiting to run
This commit is contained in:
parent
c1651ed993
commit
b2c944d1a6
1 changed files with 92 additions and 10 deletions
102
src/main.rs
102
src/main.rs
|
@ -1,7 +1,6 @@
|
||||||
extern crate mpd;
|
extern crate mpd;
|
||||||
|
|
||||||
use mpd::Client;
|
use mpd::{Client, Query, Song, Term};
|
||||||
// use std::net::TcpStream;
|
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
|
@ -11,24 +10,107 @@ use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Commands,
|
command: Option<Commands>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// Adds files to myapp
|
/// Toggle MPD stream
|
||||||
Add { name: Option<String> },
|
Toggle {},
|
||||||
|
/// Skip to the next track
|
||||||
|
Next {},
|
||||||
|
/// Revert to the previous track
|
||||||
|
Prev {},
|
||||||
|
/// Stops playing
|
||||||
|
Stop {},
|
||||||
|
/// Play queueueu
|
||||||
|
Play {
|
||||||
|
track: Option<u32>,
|
||||||
|
},
|
||||||
|
/// Set or get crossfade
|
||||||
|
Crossfade {
|
||||||
|
seconds: Option<i64>,
|
||||||
|
},
|
||||||
|
Update {},
|
||||||
|
/// Return currently playing song
|
||||||
|
Current {},
|
||||||
|
/// Query database
|
||||||
|
Search {
|
||||||
|
#[arg(trailing_var_arg = true)]
|
||||||
|
query: Vec<String>,
|
||||||
|
},
|
||||||
|
List {},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut conn = Client::connect("localhost:6600").unwrap();
|
let mut conn = Client::connect("localhost:6600").unwrap();
|
||||||
|
|
||||||
conn.toggle_pause().unwrap();
|
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
match &cli.command {
|
|
||||||
Commands::Add { name } => {
|
if let Some(cmd) = &cli.command {
|
||||||
println!("'myapp add' was used, name is: {:?}", name)
|
match cmd {
|
||||||
|
Commands::Play { track } => {
|
||||||
|
if let Some(i) = track {
|
||||||
|
conn.switch(*i).unwrap()
|
||||||
|
} else {
|
||||||
|
conn.play().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Commands::Stop {} => conn.stop().unwrap(),
|
||||||
|
|
||||||
|
Commands::Toggle {} => conn.toggle_pause().unwrap(),
|
||||||
|
|
||||||
|
Commands::Next {} => conn.next().unwrap(),
|
||||||
|
|
||||||
|
Commands::Prev {} => conn.prev().unwrap(),
|
||||||
|
|
||||||
|
Commands::List {} => print_songs(conn.queue().unwrap()),
|
||||||
|
|
||||||
|
Commands::Update {} => {
|
||||||
|
let thing = conn.update().unwrap();
|
||||||
|
println!("{}", thing)
|
||||||
|
}
|
||||||
|
|
||||||
|
Commands::Current {} => {
|
||||||
|
println!("{}", format_song(conn.currentsong().unwrap().unwrap()))
|
||||||
|
}
|
||||||
|
|
||||||
|
Commands::Search { query } => {
|
||||||
|
let mut result: Vec<String> = vec![];
|
||||||
|
let query = query.join(" ");
|
||||||
|
let window = (0, conn.stats().unwrap().songs);
|
||||||
|
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::Crossfade { seconds } => {
|
||||||
|
if let Some(crossfade) = seconds {
|
||||||
|
conn.crossfade(*crossfade).unwrap()
|
||||||
|
} else {
|
||||||
|
if let Some(crossfade) = conn.status().unwrap().crossfade {
|
||||||
|
println!("Crossfade: {}", crossfade.as_secs());
|
||||||
|
} else {
|
||||||
|
println!("Crossfade disabled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("{}", format_song(conn.currentsong().unwrap().unwrap()));
|
||||||
|
println!("{:?}", conn.stats().unwrap().songs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_songs(songs: Vec<Song>) -> () {
|
||||||
|
songs
|
||||||
|
.iter()
|
||||||
|
.for_each(|x| println!("{}", format_song(x.clone())));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_song(song: Song) -> String {
|
||||||
|
format!("{} - {}", song.artist.unwrap(), song.title.unwrap())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue