Wip
This commit is contained in:
parent
96bae9a045
commit
9c91f660d8
5 changed files with 277 additions and 34 deletions
13
.github/workflows/build_nix.yml
vendored
13
.github/workflows/build_nix.yml
vendored
|
@ -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
|
|
129
Cargo.lock
generated
129
Cargo.lock
generated
|
@ -52,6 +52,12 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bufstream"
|
name = "bufstream"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
|
@ -104,6 +110,82 @@ version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
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]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
@ -116,6 +198,46 @@ version = "1.70.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
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]]
|
[[package]]
|
||||||
name = "mpd"
|
name = "mpd"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -130,6 +252,7 @@ name = "noise"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
"libnotify",
|
||||||
"mpd",
|
"mpd",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -139,6 +262,12 @@ version = "1.70.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.95"
|
version = "1.0.95"
|
||||||
|
|
|
@ -5,4 +5,5 @@ edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.39", features = ["derive"] }
|
clap = { version = "4.5.39", features = ["derive"] }
|
||||||
|
libnotify = "1.0.3"
|
||||||
mpd = "0.1.0"
|
mpd = "0.1.0"
|
||||||
|
|
28
flake.nix
28
flake.nix
|
@ -5,18 +5,34 @@
|
||||||
utils.url = "github:numtide/flake-utils";
|
utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, utils, naersk }:
|
outputs =
|
||||||
utils.lib.eachDefaultSystem (system:
|
{
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
utils,
|
||||||
|
naersk,
|
||||||
|
}:
|
||||||
|
utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
naersk-lib = pkgs.callPackage naersk { };
|
naersk-lib = pkgs.callPackage naersk { };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
defaultPackage = naersk-lib.buildPackage ./.;
|
defaultPackage = naersk-lib.buildPackage ./.;
|
||||||
devShell = with pkgs; mkShell {
|
devShell =
|
||||||
buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ];
|
with pkgs;
|
||||||
RUST_SRC_PATH = rustPlatform.rustLibSrc;
|
mkShell {
|
||||||
};
|
buildInputs = [
|
||||||
|
cargo
|
||||||
|
rustc
|
||||||
|
rustfmt
|
||||||
|
pre-commit
|
||||||
|
rustPackages.clippy
|
||||||
|
libnotify
|
||||||
|
];
|
||||||
|
RUST_SRC_PATH = rustPlatform.rustLibSrc;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
140
src/main.rs
140
src/main.rs
|
@ -1,6 +1,8 @@
|
||||||
|
extern crate libnotify;
|
||||||
extern crate mpd;
|
extern crate mpd;
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::{io, usize};
|
||||||
|
|
||||||
use mpd::{Client, Query, Song, Term};
|
use mpd::{Client, Query, Song, Term};
|
||||||
|
|
||||||
|
@ -16,6 +18,7 @@ struct Cli {
|
||||||
|
|
||||||
#[arg(short, long, global = true)]
|
#[arg(short, long, global = true)]
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
|
///hostname where MPD listens at
|
||||||
#[arg(short = 'H', long, global = true)]
|
#[arg(short = 'H', long, global = true)]
|
||||||
host: Option<String>,
|
host: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -46,9 +49,26 @@ enum Commands {
|
||||||
///Only return the first n results
|
///Only return the first n results
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
max: Option<u32>,
|
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 {},
|
List {},
|
||||||
|
Add {
|
||||||
|
#[arg(short, long)]
|
||||||
|
position: Option<u32>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -59,7 +79,14 @@ fn main() {
|
||||||
None => String::from("localhost:6600"),
|
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 {
|
if let Some(cmd) = &cli.command {
|
||||||
match cmd {
|
match cmd {
|
||||||
|
@ -73,25 +100,47 @@ fn main() {
|
||||||
|
|
||||||
Commands::Stop {} => conn.stop().unwrap(),
|
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::Next {} => conn.next().unwrap(),
|
||||||
|
|
||||||
Commands::Prev {} => conn.prev().unwrap(),
|
Commands::Prev {} => conn.prev().unwrap(),
|
||||||
|
|
||||||
Commands::List {} => print_songs(conn.queue().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 {} => {
|
Commands::Update {} => {
|
||||||
let thing = conn.update().unwrap();
|
let thing = conn.update().unwrap();
|
||||||
println!("{}", thing)
|
println!("{thing}")
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Current {} => {
|
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 result: Vec<String> = vec![];
|
||||||
|
let mut songs: Vec<Song> = vec![];
|
||||||
let query = query.join(" ");
|
let query = query.join(" ");
|
||||||
// I want to return all results by default
|
// I want to return all results by default
|
||||||
let window = (
|
let window = (
|
||||||
|
@ -102,11 +151,43 @@ fn main() {
|
||||||
conn.stats().unwrap().songs
|
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()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|x| result.push(x.file.clone()));
|
.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 } => {
|
Commands::Crossfade { seconds } => {
|
||||||
|
@ -120,12 +201,36 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Commands::Add { position } => {
|
||||||
|
// insert_or_append(conn, *position);
|
||||||
|
println!("{:?}", position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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>) -> () {
|
fn print_songs(songs: Vec<Song>) -> () {
|
||||||
songs
|
songs
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -152,7 +257,7 @@ fn get_status(mut client: Client, verbose: bool) -> String {
|
||||||
Some((stamp, total)) => {
|
Some((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}")
|
||||||
}
|
}
|
||||||
None => "".to_string(),
|
None => "".to_string(),
|
||||||
};
|
};
|
||||||
|
@ -175,9 +280,14 @@ fn get_status(mut client: Client, verbose: bool) -> String {
|
||||||
));
|
));
|
||||||
|
|
||||||
output.push(format!(
|
output.push(format!(
|
||||||
"[{:?}] {}",
|
"[{status}] {duration}",
|
||||||
client.status().unwrap().state,
|
status = {
|
||||||
duration
|
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 minutes = seconds / 60;
|
||||||
let rem_seconds = 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