forked from ghostmkg/programming-language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnow_playing.rs
44 lines (39 loc) · 1.32 KB
/
now_playing.rs
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
use mpris::PlayerFinder;
use notify_rust::Notification;
fn main() {
let player = PlayerFinder::new()
.expect("Could not connect to D-Bus")
.find_active()
.expect("Could not find active player");
println!(
"Showing event stream for player {}...\n(Exit with Ctrl-C)\n",
player.identity()
);
let events = player.events().expect("Could not start event stream");
for event in events {
match event {
Ok(event) => match event {
mpris::Event::TrackChanged(metadata) => {
if !metadata.art_url().unwrap().is_empty()
&& metadata.track_id().is_some()
&& !metadata.title().unwrap().is_empty()
{
let _ = Notification::new()
.summary("Now playing")
.body(metadata.title().unwrap())
.icon("emblem-music-symbolic")
.show();
} else {
continue;
};
}
_ => {}
},
Err(err) => {
println!("D-Bus error: {}. Aborting.", err);
break;
}
}
}
println!("Event stream ended.");
}