Fix track detection

This commit is contained in:
2025-09-03 08:59:19 +01:00
parent d8bb1c3232
commit ed559c09c4

27
main.go
View File

@@ -1125,6 +1125,13 @@ func main() {
})
mycurrentplayingsong := fyne.NewMenuItem("Get currently playing song", func() {
// BEGIN PLATFORM SPECIFIC CODE
if os.PathSeparator == '\\' && os.PathListSeparator == ';' { // Windows
dialog.ShowError(errors.New("This feature is not supported on your operating system"), w)
return
}
// END PLATFORM SPECIFIC CODE
client, err := mpris.NewClient()
if err != nil {
dialog.ShowError(err, w)
@@ -1137,16 +1144,26 @@ func main() {
newtext := ""
title, t_ok := player.RawMetadata()["xesam:title"]
artist, a_ok := player.RawMetadata()["xesam:artist"]
if t_ok && a_ok {
newtext = fmt.Sprintf("I'm currently listening to %s by %s", title.String(), artist.String())
album, al_ok := player.RawMetadata()["xesam:album"]
artists := []string{}
if a_ok{
artist.Store(&artists)
}
if t_ok && a_ok && al_ok && album.String() != "\"\""{
newtext = fmt.Sprintf("I'm currently listening to %s by %s, in the %s album", strings.Trim(title.String(), "\""), strings.Join(artists, ","), album)
} else if t_ok && a_ok {
newtext = fmt.Sprintf("I'm currently listening to %s by %s", strings.Trim(title.String(), "\""), strings.Join(artists, ",") )
} else if t_ok {
newtext = fmt.Sprintf("I'm currently listening to %s", title.String())
newtext = fmt.Sprintf("I'm currently listening to %s", strings.Trim(title.String(), "\""))
} else if a_ok {
newtext = fmt.Sprintf("I'm currently listening to a song by %s", artist.String())
newtext = fmt.Sprintf("I'm currently listening to a song by %s", artists[0])
} else {
dialog.ShowError(errors.New("error: There's a playing song, but we could not get the artist or title information."), w)
dialog.ShowError(errors.New("error: There's a playing song, but we could not get any information."), w)
return
}
entry.SetText(newtext)
SendCallback()
entry.SetText(old)