Skip to content

Commit

Permalink
Support songs without artist/name
Browse files Browse the repository at this point in the history
  • Loading branch information
altfoxie committed Feb 28, 2023
1 parent cadb706 commit 5249f86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions AM Rich Presence.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleShortVersionString</key>
<string>0.3</string>
<string>0.4</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>IFMajorVersion</key>
<integer>0</integer>
<key>IFMinorVersion</key>
<integer>3</integer>
<integer>4</integer>
<key>NSHighResolutionCapable</key><true/>
<key>NSSupportsAutomaticGraphicsSwitching</key><true/>
<key>LSUIElement</key>
Expand Down
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"net/url"
"strings"
"time"

_ "embed"
Expand Down Expand Up @@ -56,7 +57,7 @@ func onReady() {
continue
}

if result.name == "" || result.artist == "" {
if result.name == "" && result.artist == "" {
state.SetTitle("No song")
client.Close()
continue
Expand All @@ -68,6 +69,13 @@ func onReady() {
}

song := result.artist + " – " + result.name
switch {
case result.artist == "":
song = result.name
case result.name == "":
song = result.artist
}

state.SetTitle(fmt.Sprintf("%s (%d:%02d / %d:%02d)",
song, int(result.position/60), int(result.position)%60,
int(result.duration/60), int(result.duration)%60))
Expand Down Expand Up @@ -102,11 +110,12 @@ func onReady() {
}

artwork, _ := cache.Get(song)
query := strings.TrimSpace(result.artist + " " + result.name)
if artwork == "" {
artwork = artworkSearchITunes(result.artist + " " + result.name)
artwork = artworkSearchITunes(query)
}
if artwork == "" {
artwork = artworkSearchMusixmatch(result.artist + " " + result.name)
artwork = artworkSearchMusixmatch(query)
}
if artwork != "" {
cache.Set(song, artwork)
Expand Down

0 comments on commit 5249f86

Please sign in to comment.