🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
feat(plugins): add path to Scrobbler and Lyrics plugin TrackInfo (#5339)
Jorge Pardo Pardo85e9982b434f
diff --git a/plugins/capabilities/lyrics.yaml b/plugins/capabilities/lyrics.yamlindex e4f88476c..4ac907559 100644--- a/plugins/capabilities/lyrics.yaml+++ b/plugins/capabilities/lyrics.yaml@@ -102,6 +102,11 @@ components:mbzReleaseTrackId:type: stringdescription: MBZReleaseTrackID is the MusicBrainz release track ID.+ path:+ type: string+ description: |-+ Path is the full path to the track file, relative to the library root.+ Only included if the plugin has library permission with filesystem access for the track's library.required:- id- titlediff --git a/plugins/capabilities/scrobbler.go b/plugins/capabilities/scrobbler.goindex 8091efe50..34cf60015 100644--- a/plugins/capabilities/scrobbler.go+++ b/plugins/capabilities/scrobbler.go@@ -68,6 +68,9 @@ type TrackInfo struct {MBZReleaseGroupID string `json:"mbzReleaseGroupId,omitempty"`// MBZReleaseTrackID is the MusicBrainz release track ID.MBZReleaseTrackID string `json:"mbzReleaseTrackId,omitempty"`+ // Path is the full path to the track file, relative to the library root.+ // Only included if the plugin has library permission with filesystem access for the track's library.+ Path string `json:"path,omitempty"`}// NowPlayingRequest is the request for now playing notification.diff --git a/plugins/capabilities/scrobbler.yaml b/plugins/capabilities/scrobbler.yamlindex 5de351a5f..f62da1745 100644--- a/plugins/capabilities/scrobbler.yaml+++ b/plugins/capabilities/scrobbler.yaml@@ -128,6 +128,11 @@ components:mbzReleaseTrackId:type: stringdescription: MBZReleaseTrackID is the MusicBrainz release track ID.+ path:+ type: string+ description: |-+ Path is the full path to the track file, relative to the library root.+ Only included if the plugin has library permission with filesystem access for the track's library.required:- id- titlediff --git a/plugins/lyrics_adapter.go b/plugins/lyrics_adapter.goindex aa9930664..43ebc0e4b 100644--- a/plugins/lyrics_adapter.go+++ b/plugins/lyrics_adapter.go@@ -31,7 +31,7 @@ type LyricsPlugin struct {// using model.ToLyrics.func (l *LyricsPlugin) GetLyrics(ctx context.Context, mf *model.MediaFile) (model.LyricList, error) {req := capabilities.GetLyricsRequest{- Track: mediaFileToTrackInfo(mf),+ Track: mediaFileToTrackInfo(l.plugin, mf),}resp, err := callPluginFunction[capabilities.GetLyricsRequest, capabilities.GetLyricsResponse](ctx, l.plugin, FuncLyricsGetLyrics, req,diff --git a/plugins/manager_loader.go b/plugins/manager_loader.goindex 59f48453f..ccda9e4cb 100644--- a/plugins/manager_loader.go+++ b/plugins/manager_loader.go@@ -301,7 +301,7 @@ func (m *Manager) loadPluginWithConfig(p *model.Plugin) error {}// Configure filesystem access for library permission- if pkg.Manifest.Permissions != nil && pkg.Manifest.Permissions.Library != nil && pkg.Manifest.Permissions.Library.Filesystem {+ if pkg.Manifest.HasLibraryFilesystemPermission() {adminCtx := adminContext(ctx)libraries, err := m.ds.Library(adminCtx).GetAll()if err != nil {@@ -384,6 +384,7 @@ func (m *Manager) loadPluginWithConfig(p *model.Plugin) error {metrics: m.metrics,allowedUserIDs: allowedUsers,allUsers: p.AllUsers,+ libraries: newLibraryAccess(allowedLibraries, p.AllLibraries),}m.mu.Unlock()diff --git a/plugins/manager_plugin.go b/plugins/manager_plugin.goindex 08c0073b6..1d4a8c301 100644--- a/plugins/manager_plugin.go+++ b/plugins/manager_plugin.go@@ -21,6 +21,7 @@ type plugin struct {metrics PluginMetricsRecorderallowedUserIDs []string // User IDs this plugin can access (from DB configuration)allUsers bool // If true, plugin can access all users+ libraries libraryAccess}// instance creates a new plugin instance for the given context.@@ -47,3 +48,30 @@ func (p *plugin) Close() error {}return errors.Join(errs...)}++func (p *plugin) hasLibraryFilesystemAccess(libID int) bool {+ return p.manifest.HasLibraryFilesystemPermission() && p.libraries.contains(libID)+}++// libraryAccess captures the set of libraries a plugin is permitted to see,+// precomputed at load time for O(1) lookup.+type libraryAccess struct {+ allLibraries bool+ libraryIDSet map[int]struct{}+}++func newLibraryAccess(allowedLibraryIDs []int, allLibraries bool) libraryAccess {+ set := make(map[int]struct{}, len(allowedLibraryIDs))+ for _, id := range allowedLibraryIDs {+ set[id] = struct{}{}+ }+ return libraryAccess{allLibraries: allLibraries, libraryIDSet: set}+}++func (a libraryAccess) contains(libID int) bool {+ if a.allLibraries {+ return true+ }+ _, ok := a.libraryIDSet[libID]+ return ok+}diff --git a/plugins/manager_plugin_test.go b/plugins/manager_plugin_test.gonew file mode 100644index 000000000..513b8cb8e--- /dev/null+++ b/plugins/manager_plugin_test.go@@ -0,0 +1,34 @@+package plugins++import (+ . "github.com/onsi/ginkgo/v2"+ . "github.com/onsi/gomega"+)++var _ = Describe("plugin", func() {+ Describe("hasLibraryFilesystemAccess", func() {+ fsManifest := &Manifest{+ Permissions: &Permissions{+ Library: &LibraryPermission{Filesystem: true},+ },+ }++ It("returns false when the manifest does not grant filesystem permission", func() {+ p := &plugin{manifest: &Manifest{}, libraries: newLibraryAccess(nil, true)}+ Expect(p.hasLibraryFilesystemAccess(1)).To(BeFalse())+ })++ It("returns true for any library when allLibraries is set", func() {+ p := &plugin{manifest: fsManifest, libraries: newLibraryAccess(nil, true)}+ Expect(p.hasLibraryFilesystemAccess(1)).To(BeTrue())+ Expect(p.hasLibraryFilesystemAccess(42)).To(BeTrue())+ })++ It("returns true only for libraries in the allowed list", func() {+ p := &plugin{manifest: fsManifest, libraries: newLibraryAccess([]int{1, 3}, false)}+ Expect(p.hasLibraryFilesystemAccess(1)).To(BeTrue())+ Expect(p.hasLibraryFilesystemAccess(3)).To(BeTrue())+ Expect(p.hasLibraryFilesystemAccess(2)).To(BeFalse())+ })+ })+})diff --git a/plugins/manifest.go b/plugins/manifest.goindex 375e73e7f..7484718e3 100644--- a/plugins/manifest.go+++ b/plugins/manifest.go@@ -86,3 +86,10 @@ func ValidateWithCapabilities(m *Manifest, capabilities []Capability) error {func (m *Manifest) HasExperimentalThreads() bool {return m.Experimental != nil && m.Experimental.Threads != nil}++// HasLibraryFilesystemPermission checks if the manifest grants filesystem permission for libraries.+func (m *Manifest) HasLibraryFilesystemPermission() bool {+ return m.Permissions != nil &&+ m.Permissions.Library != nil &&+ m.Permissions.Library.Filesystem+}diff --git a/plugins/pdk/go/lyrics/lyrics.go b/plugins/pdk/go/lyrics/lyrics.goindex 4f5aa6302..188371fee 100644--- a/plugins/pdk/go/lyrics/lyrics.go+++ b/plugins/pdk/go/lyrics/lyrics.go@@ -68,6 +68,9 @@ type TrackInfo struct {MBZReleaseGroupID string `json:"mbzReleaseGroupId,omitempty"`// MBZReleaseTrackID is the MusicBrainz release track ID.MBZReleaseTrackID string `json:"mbzReleaseTrackId,omitempty"`+ // Path is the full path to the track file, relative to the library root.+ // Only included if the plugin has library permission with filesystem access for the track's library.+ Path string `json:"path,omitempty"`}// Lyrics requires all methods to be implemented.diff --git a/plugins/pdk/go/lyrics/lyrics_stub.go b/plugins/pdk/go/lyrics/lyrics_stub.goindex 1fdf184e5..91eec4997 100644--- a/plugins/pdk/go/lyrics/lyrics_stub.go+++ b/plugins/pdk/go/lyrics/lyrics_stub.go@@ -65,6 +65,9 @@ type TrackInfo struct {MBZReleaseGroupID string `json:"mbzReleaseGroupId,omitempty"`// MBZReleaseTrackID is the MusicBrainz release track ID.MBZReleaseTrackID string `json:"mbzReleaseTrackId,omitempty"`+ // Path is the full path to the track file, relative to the library root.+ // Only included if the plugin has library permission with filesystem access for the track's library.+ Path string `json:"path,omitempty"`}// Lyrics requires all methods to be implemented.diff --git a/plugins/pdk/go/scrobbler/scrobbler.go b/plugins/pdk/go/scrobbler/scrobbler.goindex c694f59d8..e16bfed4b 100644--- a/plugins/pdk/go/scrobbler/scrobbler.go+++ b/plugins/pdk/go/scrobbler/scrobbler.go@@ -92,6 +92,9 @@ type TrackInfo struct {MBZReleaseGroupID string `json:"mbzReleaseGroupId,omitempty"`// MBZReleaseTrackID is the MusicBrainz release track ID.MBZReleaseTrackID string `json:"mbzReleaseTrackId,omitempty"`+ // Path is the full path to the track file, relative to the library root.+ // Only included if the plugin has library permission with filesystem access for the track's library.+ Path string `json:"path,omitempty"`}// Scrobbler requires all methods to be implemented.diff --git a/plugins/pdk/go/scrobbler/scrobbler_stub.go b/plugins/pdk/go/scrobbler/scrobbler_stub.goindex 6d4afd818..86a71af03 100644--- a/plugins/pdk/go/scrobbler/scrobbler_stub.go+++ b/plugins/pdk/go/scrobbler/scrobbler_stub.go@@ -89,6 +89,9 @@ type TrackInfo struct {MBZReleaseGroupID string `json:"mbzReleaseGroupId,omitempty"`// MBZReleaseTrackID is the MusicBrainz release track ID.MBZReleaseTrackID string `json:"mbzReleaseTrackId,omitempty"`+ // Path is the full path to the track file, relative to the library root.+ // Only included if the plugin has library permission with filesystem access for the track's library.+ Path string `json:"path,omitempty"`}// Scrobbler requires all methods to be implemented.diff --git a/plugins/pdk/rust/nd-pdk-capabilities/src/lyrics.rs b/plugins/pdk/rust/nd-pdk-capabilities/src/lyrics.rsindex 16882abae..fcfe553f8 100644--- a/plugins/pdk/rust/nd-pdk-capabilities/src/lyrics.rs+++ b/plugins/pdk/rust/nd-pdk-capabilities/src/lyrics.rs@@ -102,6 +102,10 @@ pub struct TrackInfo {/// MBZReleaseTrackID is the MusicBrainz release track ID.#[serde(default, skip_serializing_if = "String::is_empty")]pub mbz_release_track_id: String,+ /// Path is the full path to the track file, relative to the library root.+ /// Only included if the plugin has library permission with filesystem access for the track's library.+ #[serde(default, skip_serializing_if = "String::is_empty")]+ pub path: String,}/// Error represents an error from a capability method.diff --git a/plugins/pdk/rust/nd-pdk-capabilities/src/scrobbler.rs b/plugins/pdk/rust/nd-pdk-capabilities/src/scrobbler.rsindex 2572712d1..dd42e6803 100644--- a/plugins/pdk/rust/nd-pdk-capabilities/src/scrobbler.rs+++ b/plugins/pdk/rust/nd-pdk-capabilities/src/scrobbler.rs@@ -122,6 +122,10 @@ pub struct TrackInfo {/// MBZReleaseTrackID is the MusicBrainz release track ID.#[serde(default, skip_serializing_if = "String::is_empty")]pub mbz_release_track_id: String,+ /// Path is the full path to the track file, relative to the library root.+ /// Only included if the plugin has library permission with filesystem access for the track's library.+ #[serde(default, skip_serializing_if = "String::is_empty")]+ pub path: String,}/// Error represents an error from a capability method.diff --git a/plugins/scrobbler_adapter.go b/plugins/scrobbler_adapter.goindex 874c6603a..4f7cd4661 100644--- a/plugins/scrobbler_adapter.go+++ b/plugins/scrobbler_adapter.go@@ -80,7 +80,7 @@ func (s *ScrobblerPlugin) NowPlaying(ctx context.Context, userId string, track *username := getUsernameFromContext(ctx)input := capabilities.NowPlayingRequest{Username: username,- Track: mediaFileToTrackInfo(track),+ Track: mediaFileToTrackInfo(s.plugin, track),Position: int32(position),}@@ -93,7 +93,7 @@ func (s *ScrobblerPlugin) Scrobble(ctx context.Context, userId string, sc scrobbusername := getUsernameFromContext(ctx)input := capabilities.ScrobbleRequest{Username: username,- Track: mediaFileToTrackInfo(&sc.MediaFile),+ Track: mediaFileToTrackInfo(s.plugin, &sc.MediaFile),Timestamp: sc.TimeStamp.Unix(),}@@ -109,9 +109,11 @@ func getUsernameFromContext(ctx context.Context) string {return ""}-// mediaFileToTrackInfo converts a model.MediaFile to capabilities.TrackInfo-func mediaFileToTrackInfo(mf *model.MediaFile) capabilities.TrackInfo {- return capabilities.TrackInfo{+// mediaFileToTrackInfo converts a model.MediaFile to capabilities.TrackInfo.+// Path is populated only when the plugin is allowed filesystem access to the+// track's library.+func mediaFileToTrackInfo(p *plugin, mf *model.MediaFile) capabilities.TrackInfo {+ ti := capabilities.TrackInfo{ID: mf.ID,Title: mf.Title,Album: mf.Album,@@ -127,6 +129,10 @@ func mediaFileToTrackInfo(mf *model.MediaFile) capabilities.TrackInfo {MBZReleaseGroupID: mf.MbzReleaseGroupID,MBZReleaseTrackID: mf.MbzReleaseTrackID,}+ if p.hasLibraryFilesystemAccess(mf.LibraryID) {+ ti.Path = mf.Path+ }+ return ti}// participantsToArtistRefs converts a ParticipantList to a slice of ArtistRefdiff --git a/plugins/scrobbler_adapter_test.go b/plugins/scrobbler_adapter_test.goindex ab8dc6f88..0ee229022 100644--- a/plugins/scrobbler_adapter_test.go+++ b/plugins/scrobbler_adapter_test.go@@ -240,6 +240,40 @@ var _ = Describe("ScrobblerPlugin", Ordered, func() {Expect(names).ToNot(ContainElement("test-metadata-agent"))})})++ Describe("mediaFileToTrackInfo", func() {+ var track *model.MediaFile++ BeforeEach(func() {+ track = &model.MediaFile{+ ID: "track-1",+ Title: "Test Song",+ Path: "/music/test.flac",+ LibraryID: 1,+ }+ })++ fsManifest := &Manifest{+ Permissions: &Permissions{+ Library: &LibraryPermission{Filesystem: true},+ },+ }++ It("includes Path when the plugin has filesystem access to the track's library", func() {+ p := &plugin{manifest: fsManifest, libraries: newLibraryAccess([]int{1}, false)}+ Expect(mediaFileToTrackInfo(p, track).Path).To(Equal("/music/test.flac"))+ })++ It("omits Path when the plugin lacks filesystem permission", func() {+ p := &plugin{manifest: &Manifest{}, libraries: newLibraryAccess([]int{1}, false)}+ Expect(mediaFileToTrackInfo(p, track).Path).To(BeEmpty())+ })++ It("omits Path when the track's library is not in the allowed set", func() {+ p := &plugin{manifest: fsManifest, libraries: newLibraryAccess([]int{2}, false)}+ Expect(mediaFileToTrackInfo(p, track).Path).To(BeEmpty())+ })+ })})var _ = Describe("mapScrobblerError", func() {