A Rust program to query media details

This commit is contained in:
Ferit Yiğit BALABAN 2022-07-17 15:54:33 +03:00
parent 84d079f08e
commit 8ac4d63c09
2 changed files with 26 additions and 0 deletions

BIN
nowplaying Executable file

Binary file not shown.

26
nowplaying.rs Normal file
View File

@ -0,0 +1,26 @@
use std::process::Command;
fn main() {
let output0 = Command::new("/usr/bin/playerctl")
.arg("status")
.output()
.expect("err: call playerctl status");
let status = String::from_utf8_lossy(&output0.stdout);
if status == "Playing\n" {
let output1 = Command::new("/usr/bin/playerctl")
.arg("-f")
.arg("'{{trunc(xesam:artist, 15)}} - {{trunc(xesam:title, 30)}}'")
.arg("metadata")
.output()
.expect("err: call playerctl metadata");
let music = &String::from_utf8(output1.stdout).unwrap();
println!("{}", &music[1..music.len() - 2]);
} else if status == "Paused\n" {
println!("Paused\n");
} else {
println!("");
}
}