Extract and display radio ICY metadata (#845)

* extract and display radio ICY metadata

* fix crash when casting radio station
This commit is contained in:
Drew Weymouth
2026-02-05 07:51:15 -08:00
committed by GitHub
parent 08c8c6e421
commit 3c46889014
8 changed files with 120 additions and 9 deletions
+19
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"log"
"math/rand"
"strings"
"time"
"github.com/dweymouth/supersonic/backend/mediaprovider"
@@ -103,6 +104,8 @@ type playbackEngine struct {
onStopped []func()
onPlaying []func()
onQueueChange []func()
onRadioMetadataChange []func(radioName, title, artist string)
}
func NewPlaybackEngine(
@@ -698,6 +701,22 @@ func (p *playbackEngine) setTrack(idx int, next bool, startTime float64) error {
url = filepath
}
}
if mpvP, ok := p.player.(*mpv.Player); ok && !isTrack {
mpvP.ObserveIcyRadioTitle(func(icytitle string) {
var title, artist string
if s := strings.Split(icytitle, " - "); len(s) == 2 {
title, artist = s[1], s[0]
} else {
title = icytitle
}
log.Println("Radio metadata changed: ", icytitle)
for _, cb := range p.onRadioMetadataChange {
cb(meta.Name, title, artist)
}
})
} else if ok {
mpvP.UnobserveIcyRadioTitle()
}
if url == "" {
return errors.New("no stream URL")
}