From 16efa0d0e998d79c0f2e8fe474691999fff783c9 Mon Sep 17 00:00:00 2001 From: tim Date: Fri, 23 Jan 2026 22:26:16 +0100 Subject: [PATCH] feat(subsonic): support separate admin credentials for library scans --- sample.env | 4 ++++ src/client/subsonic.go | 16 +++++++++++++++- src/config/config.go | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sample.env b/sample.env index 61c7a70..29b6169 100644 --- a/sample.env +++ b/sample.env @@ -17,6 +17,10 @@ SYSTEM_URL= SYSTEM_USERNAME= # Password for the user (required for subsonic, recommended for plex) SYSTEM_PASSWORD= +# Optional admin username for systems like Navidrome/Subsonic (used only for triggering library scans) +# ADMIN_SYSTEM_USERNAME= +# Optional admin password for systems like Navidrome/Subsonic (used only for triggering library scans) +# ADMIN_SYSTEM_PASSWORD= # API Key from your media system (required for emby and jellyfin, optional for plex) API_KEY= # Name of the music library in your system (emby, jellyfin, plex) diff --git a/src/client/subsonic.go b/src/client/subsonic.go index 51417cd..ba47d66 100644 --- a/src/client/subsonic.go +++ b/src/client/subsonic.go @@ -158,8 +158,22 @@ func (c *Subsonic) SearchSongs(tracks []*models.Track) error { } func (c *Subsonic) RefreshLibrary() error { + if c.Cfg.AdminCreds.User != "" && c.Cfg.AdminCreds.Password != "" { + adminCfg := c.Cfg + adminCfg.Creds = config.Credentials{User: c.Cfg.AdminCreds.User, Password: c.Cfg.AdminCreds.Password} + adminClient := NewSubsonic(adminCfg, c.HttpClient) + + if err := adminClient.GetAuth(); err != nil { + return err + } + return adminClient.startScan() + } + + return c.startScan() +} + +func (c *Subsonic) startScan() error { reqParam := "startScan?f=json" - if _, err := c.subsonicRequest(reqParam); err != nil { return err } diff --git a/src/config/config.go b/src/config/config.go index e92e21b..99fb395 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -49,6 +49,7 @@ type ClientConfig struct { Sleep int `env:"SLEEP" env-default:"2"` HTTPTimeout int `env:"CLIENT_HTTP_TIMEOUT" env-default:"10"` Creds Credentials + AdminCreds AdminCredentials Subsonic SubsonicConfig } @@ -61,6 +62,11 @@ type Credentials struct { Salt string } +type AdminCredentials struct { + User string `env:"ADMIN_SYSTEM_USERNAME"` + Password string `env:"ADMIN_SYSTEM_PASSWORD"` +} + type SubsonicConfig struct { Version string `env:"SUBSONIC_VERSION" env-default:"1.16.1"`