diff --git a/plugins/capabilities.go b/plugins/capabilities.go index 00a3becbe..d52b27b07 100644 --- a/plugins/capabilities.go +++ b/plugins/capabilities.go @@ -4,41 +4,13 @@ package plugins // Capabilities are detected by checking which functions a plugin exports. type Capability string -const ( - // CapabilityMetadataAgent indicates the plugin can provide artist/album metadata. - // Detected when the plugin exports at least one of the metadata agent functions. - CapabilityMetadataAgent Capability = "MetadataAgent" - - // CapabilityScrobbler indicates the plugin can receive scrobble events. - // Detected when the plugin exports at least one of the scrobbler functions. - CapabilityScrobbler Capability = "Scrobbler" - - // CapabilityScheduler indicates the plugin can receive scheduled event callbacks. - // Detected when the plugin exports the scheduler callback function. - CapabilityScheduler Capability = "Scheduler" -) - // capabilityFunctions maps each capability to its required/optional functions. // A plugin has a capability if it exports at least one of these functions. -var capabilityFunctions = map[Capability][]string{ - CapabilityMetadataAgent: { - FuncGetArtistMBID, - FuncGetArtistURL, - FuncGetArtistBiography, - FuncGetSimilarArtists, - FuncGetArtistImages, - FuncGetArtistTopSongs, - FuncGetAlbumInfo, - FuncGetAlbumImages, - }, - CapabilityScrobbler: { - FuncScrobblerIsAuthorized, - FuncScrobblerNowPlaying, - FuncScrobblerScrobble, - }, - CapabilityScheduler: { - FuncSchedulerCallback, - }, +var capabilityFunctions = map[Capability][]string{} + +// registerCapability registers a capability with its associated functions. +func registerCapability(cap Capability, functions ...string) { + capabilityFunctions[cap] = functions } // functionExistsChecker is an interface for checking if a function exists in a plugin. diff --git a/plugins/host_scheduler.go b/plugins/host_scheduler.go index 1fbe23c23..71d2f5a08 100644 --- a/plugins/host_scheduler.go +++ b/plugins/host_scheduler.go @@ -12,8 +12,19 @@ import ( "github.com/navidrome/navidrome/scheduler" ) +// CapabilityScheduler indicates the plugin can receive scheduled event callbacks. +// Detected when the plugin exports the scheduler callback function. +const CapabilityScheduler Capability = "Scheduler" + const FuncSchedulerCallback = "nd_scheduler_callback" +func init() { + registerCapability( + CapabilityScheduler, + FuncSchedulerCallback, + ) +} + // timeAfterFunc is a variable for time.AfterFunc, allowing tests to override it. var timeAfterFunc = time.AfterFunc diff --git a/plugins/metadata_agent.go b/plugins/metadata_agent.go index 4fe617128..05aed70de 100644 --- a/plugins/metadata_agent.go +++ b/plugins/metadata_agent.go @@ -7,6 +7,10 @@ import ( "github.com/navidrome/navidrome/core/agents" ) +// CapabilityMetadataAgent indicates the plugin can provide artist/album metadata. +// Detected when the plugin exports at least one of the metadata agent functions. +const CapabilityMetadataAgent Capability = "MetadataAgent" + // Export function names (snake_case as per design) const ( FuncGetArtistMBID = "nd_get_artist_mbid" @@ -19,6 +23,20 @@ const ( FuncGetAlbumImages = "nd_get_album_images" ) +func init() { + registerCapability( + CapabilityMetadataAgent, + FuncGetArtistMBID, + FuncGetArtistURL, + FuncGetArtistBiography, + FuncGetSimilarArtists, + FuncGetArtistImages, + FuncGetArtistTopSongs, + FuncGetAlbumInfo, + FuncGetAlbumImages, + ) +} + // MetadataAgent is an adapter that wraps an Extism plugin and implements // the agents interfaces for metadata retrieval. type MetadataAgent struct { diff --git a/plugins/scrobbler_adapter.go b/plugins/scrobbler_adapter.go index 0e54c9296..9bb7a6abe 100644 --- a/plugins/scrobbler_adapter.go +++ b/plugins/scrobbler_adapter.go @@ -9,6 +9,10 @@ import ( "github.com/navidrome/navidrome/model/request" ) +// CapabilityScrobbler indicates the plugin can receive scrobble events. +// Detected when the plugin exports at least one of the scrobbler functions. +const CapabilityScrobbler Capability = "Scrobbler" + // Scrobbler function names (snake_case as per design) const ( FuncScrobblerIsAuthorized = "nd_scrobbler_is_authorized" @@ -16,6 +20,15 @@ const ( FuncScrobblerScrobble = "nd_scrobbler_scrobble" ) +func init() { + registerCapability( + CapabilityScrobbler, + FuncScrobblerIsAuthorized, + FuncScrobblerNowPlaying, + FuncScrobblerScrobble, + ) +} + // ScrobblerPlugin is an adapter that wraps an Extism plugin and implements // the scrobbler.Scrobbler interface for scrobbling to external services. type ScrobblerPlugin struct {