Extract and display radio ICY metadata (#845)
* extract and display radio ICY metadata * fix crash when casting radio station
This commit is contained in:
+27
-3
@@ -43,6 +43,11 @@ type MPRISHandler struct {
|
||||
pm *PlaybackManager
|
||||
s *server.Server
|
||||
evt *events.EventHandler
|
||||
|
||||
// current radio metadata
|
||||
radioStationName string
|
||||
radioIcyTitle string
|
||||
radioIcyArtist string
|
||||
}
|
||||
|
||||
func NewMPRISHandler(playerName string, pm *PlaybackManager) *MPRISHandler {
|
||||
@@ -66,6 +71,14 @@ func NewMPRISHandler(playerName string, pm *PlaybackManager) *MPRISHandler {
|
||||
m.evt.Player.OnTitle()
|
||||
}
|
||||
})
|
||||
pm.OnRadioMetadataChange(func(radioName, title, artist string) {
|
||||
m.radioStationName = radioName
|
||||
m.radioIcyTitle = title
|
||||
m.radioIcyArtist = artist
|
||||
if m.connErr == nil {
|
||||
m.evt.Player.OnTitle()
|
||||
}
|
||||
})
|
||||
pm.OnVolumeChange(func(vol int) {
|
||||
if m.connErr == nil {
|
||||
m.evt.Player.OnVolume()
|
||||
@@ -276,12 +289,23 @@ func (m *MPRISHandler) Metadata() (types.Metadata, error) {
|
||||
artURL = u
|
||||
}
|
||||
}
|
||||
|
||||
title := meta.Name
|
||||
artists := meta.Artists
|
||||
album := meta.Album
|
||||
// if playing a radio station, override title/artist with current Icy metadata if present
|
||||
if m.radioStationName == title && m.radioIcyTitle != "" {
|
||||
title = m.radioIcyTitle
|
||||
artists = []string{m.radioIcyArtist}
|
||||
album = m.radioStationName
|
||||
}
|
||||
|
||||
mprisMeta := types.Metadata{
|
||||
TrackId: dbus.ObjectPath(trackObjPath),
|
||||
Length: secondsToMicroseconds(status.Duration),
|
||||
Title: meta.Name,
|
||||
Album: meta.Album,
|
||||
Artist: meta.Artists,
|
||||
Title: title,
|
||||
Album: album,
|
||||
Artist: artists,
|
||||
DiscNumber: discNumber,
|
||||
TrackNumber: trackNumber,
|
||||
UserRating: float64(userRating) / 5,
|
||||
|
||||
Reference in New Issue
Block a user