Skip to content

Commit

Permalink
fix: handle other metadata not being present (resolves #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
TorchedSammy committed Oct 30, 2021
1 parent 346dc08 commit 130e7a3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"fmt"
"os"
"path/filepath"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -109,7 +111,11 @@ func setPresence(metadata map[string]dbus.Variant, songstamp time.Time) {
startstamp := &songstamp
endstamp := &stampTime

title := metadata["xesam:title"].Value().(string)
titleUrlEscaped := filepath.Base(metadata["xesam:url"].Value().(string))
title, _ := url.PathUnescape(titleUrlEscaped)
if songtitle, ok := metadata["xesam:title"].Value().(string); ok {
title = songtitle
}
album := ""
if abm, ok := metadata["xesam:album"].Value().(string); ok {
album = " on " + abm
Expand All @@ -118,10 +124,13 @@ func setPresence(metadata map[string]dbus.Variant, songstamp time.Time) {
startstamp, endstamp = nil, nil
}

artists := strings.Join(metadata["xesam:artist"].Value().([]string), ", ")
artistsStr := ""
if artistsArr, ok := metadata["xesam:artist"].Value().([]string); ok {
artistsStr = "by " + strings.Join(artistsArr, ", ")
}
client.SetActivity(client.Activity{
Details: title,
State: "by " + artists + album,
State: artistsStr + album,
LargeImage: "music",
LargeText: "cmus",
SmallImage: strings.ToLower(pbStat),
Expand Down

0 comments on commit 130e7a3

Please sign in to comment.