diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml deleted file mode 100644 index 87d2eba..0000000 --- a/.github/workflows/build_nix.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: "Build legacy Nix package on Ubuntu" - -on: - push: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: cachix/install-nix-action@v26 - - name: Building package - run: nix build diff --git a/Cargo.lock b/Cargo.lock index 57729d1..f597fe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,6 +52,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bufstream" version = "0.1.4" @@ -104,6 +110,82 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "gdk-pixbuf" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16160d212ae91abe9f3324c3fb233929ba322dde63585d15cda3336f8c529ed1" +dependencies = [ + "gdk-pixbuf-sys", + "glib", + "glib-sys", + "gobject-sys", + "libc", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "798f97101eea8180da363d0e80e07ec7ec6d1809306601c0100c1de5bc8b4f52" +dependencies = [ + "bitflags", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pkg-config", +] + +[[package]] +name = "gio-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a303bbf7a5e75ab3b627117ff10e495d1b9e97e1d68966285ac2b1f6270091bc" +dependencies = [ + "bitflags", + "glib-sys", + "gobject-sys", + "libc", + "pkg-config", +] + +[[package]] +name = "glib" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9b0452824cc63066940f01adc721804919f0b76cdba3cfab977b00b87f16d4a" +dependencies = [ + "bitflags", + "glib-sys", + "gobject-sys", + "lazy_static", + "libc", +] + +[[package]] +name = "glib-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9693049613ff52b93013cc3d2590366d8e530366d288438724b73f6c7dc4be8" +dependencies = [ + "bitflags", + "libc", + "pkg-config", +] + +[[package]] +name = "gobject-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60d507c87a71b1143c66ed21a969be9b99a76df234b342d733e787e6c9c7d7c2" +dependencies = [ + "bitflags", + "glib-sys", + "libc", + "pkg-config", +] + [[package]] name = "heck" version = "0.5.0" @@ -116,6 +198,46 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.172" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" + +[[package]] +name = "libnotify" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10506a4f8bc6f8f7ccc6fde3a8290378d7aed3d1a26dca606a73e2ffe140cc2d" +dependencies = [ + "gdk-pixbuf", + "gdk-pixbuf-sys", + "glib", + "glib-sys", + "gobject-sys", + "libnotify-sys", +] + +[[package]] +name = "libnotify-sys" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0a716b9b7d24ed10f1eb431e1527fa13c9a4bf2d4fa68bb3e54da1d0747383c" +dependencies = [ + "bitflags", + "gdk-pixbuf-sys", + "glib-sys", + "gobject-sys", + "libc", + "pkg-config", +] + [[package]] name = "mpd" version = "0.1.0" @@ -130,6 +252,7 @@ name = "noise" version = "0.1.0" dependencies = [ "clap", + "libnotify", "mpd", ] @@ -139,6 +262,12 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "proc-macro2" version = "1.0.95" diff --git a/Cargo.toml b/Cargo.toml index 2be2315..629f52e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ edition = "2024" [dependencies] clap = { version = "4.5.39", features = ["derive"] } +libnotify = "1.0.3" mpd = "0.1.0" diff --git a/flake.nix b/flake.nix index 680de52..a778e3f 100644 --- a/flake.nix +++ b/flake.nix @@ -5,18 +5,34 @@ utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, utils, naersk }: - utils.lib.eachDefaultSystem (system: + outputs = + { + self, + nixpkgs, + utils, + naersk, + }: + utils.lib.eachDefaultSystem ( + system: let pkgs = import nixpkgs { inherit system; }; naersk-lib = pkgs.callPackage naersk { }; in { defaultPackage = naersk-lib.buildPackage ./.; - devShell = with pkgs; mkShell { - buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ]; - RUST_SRC_PATH = rustPlatform.rustLibSrc; - }; + devShell = + with pkgs; + mkShell { + buildInputs = [ + cargo + rustc + rustfmt + pre-commit + rustPackages.clippy + libnotify + ]; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; } ); } diff --git a/src/main.rs b/src/main.rs index cd8852a..abfef2c 100644 --- a/src/main.rs +++ b/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, } @@ -46,9 +49,26 @@ enum Commands { ///Only return the first n results #[arg(short, long)] max: Option, + #[arg(short, long)] + append: bool, + #[arg(short, long)] + insert: Option, }, - ///List items in the current queueueu + /// Query database differently + Find { + ///Search query + #[arg(trailing_var_arg = true)] + query: Vec, + ///Only return the first n results + #[arg(short, long)] + max: Option, + }, + /// List items in the current queueueu List {}, + Add { + #[arg(short, long)] + position: Option, + }, } 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 = vec![]; + let mut songs: Vec = 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 = 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) { +// 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) -> () { 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}") }