Skip to content

Commit 6feb931

Browse files
authored
Merge pull request #96 from isic96/feat/subsonic-admin-credentials
Support separate admin credentials for subsonic library scans
2 parents 2c58392 + 16efa0d commit 6feb931

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

sample.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ SYSTEM_URL=
1717
SYSTEM_USERNAME=
1818
# Password for the user (required for subsonic, recommended for plex)
1919
SYSTEM_PASSWORD=
20+
# Optional admin username for systems like Navidrome/Subsonic (used only for triggering library scans)
21+
# ADMIN_SYSTEM_USERNAME=
22+
# Optional admin password for systems like Navidrome/Subsonic (used only for triggering library scans)
23+
# ADMIN_SYSTEM_PASSWORD=
2024
# API Key from your media system (required for emby and jellyfin, optional for plex)
2125
API_KEY=
2226
# Name of the music library in your system (emby, jellyfin, plex)

src/client/subsonic.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,22 @@ func (c *Subsonic) SearchSongs(tracks []*models.Track) error {
158158
}
159159

160160
func (c *Subsonic) RefreshLibrary() error {
161+
if c.Cfg.AdminCreds.User != "" && c.Cfg.AdminCreds.Password != "" {
162+
adminCfg := c.Cfg
163+
adminCfg.Creds = config.Credentials{User: c.Cfg.AdminCreds.User, Password: c.Cfg.AdminCreds.Password}
164+
adminClient := NewSubsonic(adminCfg, c.HttpClient)
165+
166+
if err := adminClient.GetAuth(); err != nil {
167+
return err
168+
}
169+
return adminClient.startScan()
170+
}
171+
172+
return c.startScan()
173+
}
174+
175+
func (c *Subsonic) startScan() error {
161176
reqParam := "startScan?f=json"
162-
163177
if _, err := c.subsonicRequest(reqParam); err != nil {
164178
return err
165179
}

src/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type ClientConfig struct {
4949
Sleep int `env:"SLEEP" env-default:"2"`
5050
HTTPTimeout int `env:"CLIENT_HTTP_TIMEOUT" env-default:"10"`
5151
Creds Credentials
52+
AdminCreds AdminCredentials
5253
Subsonic SubsonicConfig
5354
}
5455

@@ -61,6 +62,11 @@ type Credentials struct {
6162
Salt string
6263
}
6364

65+
type AdminCredentials struct {
66+
User string `env:"ADMIN_SYSTEM_USERNAME"`
67+
Password string `env:"ADMIN_SYSTEM_PASSWORD"`
68+
}
69+
6470

6571
type SubsonicConfig struct {
6672
Version string `env:"SUBSONIC_VERSION" env-default:"1.16.1"`

0 commit comments

Comments
 (0)