From fd930eefd73df9a62c1c1b21370a2389c783fcee Mon Sep 17 00:00:00 2001 From: Deluan Date: Sun, 26 Apr 2026 16:36:57 -0400 Subject: [PATCH] feat(plugins): add LibraryID to TrackInfo Add LibraryID field to TrackInfo so plugins with library filesystem access can determine which library a track belongs to. This lets plugins resolve the full filesystem path by combining the library's root path with the track's relative path. LibraryID is gated behind the same filesystem access permission check as Path. --- plugins/capabilities/scrobbler.go | 3 +++ plugins/scrobbler_adapter.go | 1 + plugins/scrobbler_adapter_test.go | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/capabilities/scrobbler.go b/plugins/capabilities/scrobbler.go index 34cf60015..ed8a4fb6c 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"` + // LibraryID is the ID of the library the track belongs to. + // Only included if the plugin has library permission with filesystem access for the track's library. + LibraryID int32 `json:"libraryId,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"` diff --git a/plugins/scrobbler_adapter.go b/plugins/scrobbler_adapter.go index 4f7cd4661..02c2b2889 100644 --- a/plugins/scrobbler_adapter.go +++ b/plugins/scrobbler_adapter.go @@ -130,6 +130,7 @@ func mediaFileToTrackInfo(p *plugin, mf *model.MediaFile) capabilities.TrackInfo MBZReleaseTrackID: mf.MbzReleaseTrackID, } if p.hasLibraryFilesystemAccess(mf.LibraryID) { + ti.LibraryID = int32(mf.LibraryID) ti.Path = mf.Path } return ti diff --git a/plugins/scrobbler_adapter_test.go b/plugins/scrobbler_adapter_test.go index 0ee229022..c56d8a900 100644 --- a/plugins/scrobbler_adapter_test.go +++ b/plugins/scrobbler_adapter_test.go @@ -259,19 +259,25 @@ var _ = Describe("ScrobblerPlugin", Ordered, func() { }, } - It("includes Path when the plugin has filesystem access to the track's library", func() { + It("includes LibraryID and 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")) + ti := mediaFileToTrackInfo(p, track) + Expect(ti.LibraryID).To(Equal(int32(1))) + Expect(ti.Path).To(Equal("/music/test.flac")) }) - It("omits Path when the plugin lacks filesystem permission", func() { + It("omits LibraryID and Path when the plugin lacks filesystem permission", func() { p := &plugin{manifest: &Manifest{}, libraries: newLibraryAccess([]int{1}, false)} - Expect(mediaFileToTrackInfo(p, track).Path).To(BeEmpty()) + ti := mediaFileToTrackInfo(p, track) + Expect(ti.LibraryID).To(BeZero()) + Expect(ti.Path).To(BeEmpty()) }) - It("omits Path when the track's library is not in the allowed set", func() { + It("omits LibraryID and 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()) + ti := mediaFileToTrackInfo(p, track) + Expect(ti.LibraryID).To(BeZero()) + Expect(ti.Path).To(BeEmpty()) }) }) })