Fix error when no track is playing
This commit is contained in:
parent
26a3381a25
commit
05dddfde6d
1 changed files with 8 additions and 2 deletions
10
src/main.rs
10
src/main.rs
|
@ -53,8 +53,14 @@ async fn get_player(_req: tide::Request<()>) -> tide::Result {
|
||||||
let song = mpd.command("currentsong").await?.into_hashmap();
|
let song = mpd.command("currentsong").await?.into_hashmap();
|
||||||
let status = mpd.command("status").await?.into_hashmap();
|
let status = mpd.command("status").await?.into_hashmap();
|
||||||
|
|
||||||
let elapsed = status["elapsed"].parse().unwrap_or(0.0);
|
let elapsed = status
|
||||||
let duration = status["duration"].parse().unwrap_or(1.0);
|
.get("elapsed")
|
||||||
|
.and_then(|e| e.parse().ok())
|
||||||
|
.unwrap_or(0.0);
|
||||||
|
let duration = status
|
||||||
|
.get("duration")
|
||||||
|
.and_then(|e| e.parse().ok())
|
||||||
|
.unwrap_or(1.0);
|
||||||
|
|
||||||
let mut template = PlayerTemplate {
|
let mut template = PlayerTemplate {
|
||||||
song: if song.is_empty() { None } else { Some(&song) },
|
song: if song.is_empty() { None } else { Some(&song) },
|
||||||
|
|
Loading…
Reference in a new issue