blob: 74f90c83aa60a33dd788a893f6965808500a2caa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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}");
}
}
|