Fix error when no track is playing

This commit is contained in:
Sijmen 2023-05-16 01:53:46 +02:00
parent 26a3381a25
commit 05dddfde6d
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
1 changed files with 8 additions and 2 deletions

View File

@ -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) },