diff options
| author | tslil <tslil@posteo.de> | 2026-07-12 18:20:30 +0100 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-07-13 19:56:12 +0100 |
| commit | e0241df8afde0483fc36cb2300b53127672486dc (patch) | |
| tree | 9fa2bec196498df5b5167b55e250bb96d56d96d5 /src/main.rs | |
Graph basedgraph
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..74f90c8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,61 @@ +use std::process::Command; + +mod config; +mod learner; +mod state; +mod trajectory; + +use crate::{config::default_state_path, state::State}; + +fn mpc_load_and_play(path: &str) { + _ = Command::new("mpc") + .arg("clear") + .output() + .expect("failed to execute mpc clear"); + + _ = Command::new("mpc") + .args(["add", path]) + .output() + .expect("failed to execute mpc add"); + + _ = Command::new("mpc") + .arg("play") + .output() + .expect("failed to execute mpc play"); +} + +fn notify(text: &str) { + if let Err(e) = Command::new("notify-send") + .args(["-t", "5000", "-a", "mood", &text]) + .status() + { + eprintln!("Failed to show notification: {e}"); + } +} + +fn main() { + let state = State::load(&default_state_path()); + let mut state = match state { + Err(e) => { + eprintln!("Failed to load state: {e}"); + State::default() + } + Ok(s) => s, + }; + + let ur = state.update_albums(); + println!("Update result: {ur}"); + + if let Some((next_album, prob)) = state.next() { + let text = format!("Now playing: {next_album} ({:.2}%)", prob * 100.0); + println!("{text}"); + mpc_load_and_play(&next_album); + notify(&text); + } else { + println!("No next album available."); + } + + if let Err(e) = state.try_save() { + eprintln!("Failed to save state: {e}"); + } +} |
