aboutsummaryrefslogtreecommitdiff
path: root/spotify.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-05-21 20:22:33 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-05-21 20:22:33 +0200
commit2d37d05726621be328312ad1a79f5f62b1882ba9 (patch)
tree532d3fb54de3dff329909f45a3fca064f319612d /spotify.go
parent76382920eac0a2b56b7d143d62d57def99e7db6a (diff)
downloadWRMS-2d37d05726621be328312ad1a79f5f62b1882ba9.tar.gz
WRMS-2d37d05726621be328312ad1a79f5f62b1882ba9.zip
allow YAML parsing of the spotify config
Diffstat (limited to 'spotify.go')
-rw-r--r--spotify.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/spotify.go b/spotify.go
index 0e4974a..d075930 100644
--- a/spotify.go
+++ b/spotify.go
@@ -25,30 +25,37 @@ const (
deviceName = "wrms"
)
-type spotifyConfig struct {
- username string
- password string
+type SpotifyConfig struct {
+ Username string `yaml:"username"`
+ Password string `yaml:"password"`
}
type SpotifyBackend struct {
session *core.Session
}
-func NewSpotify(config *spotifyConfig) (*SpotifyBackend, error) {
+func NewSpotify(config *SpotifyConfig) (*SpotifyBackend, error) {
spotify := SpotifyBackend{}
- if config != nil {
- config = &spotifyConfig{}
+ if config == nil {
+ config = &SpotifyConfig{}
}
- config.username = os.Getenv("WRMS_SPOTIFY_USER")
- config.password = os.Getenv("WRMS_SPOTIFY_PASSWORD")
+ usernameEnv := os.Getenv("WRMS_SPOTIFY_USER")
+ if usernameEnv != "" {
+ config.Username = usernameEnv
+ }
+
+ passwordEnv := os.Getenv("WRMS_SPOTIFY_PASSWORD")
+ if passwordEnv != "" {
+ config.Password = passwordEnv
+ }
- if config.username == "" || config.password == "" {
+ if config.Username == "" || config.Password == "" {
return nil, errors.New("User and password for spotify must be provided")
}
var err error
- spotify.session, err = librespot.Login(config.username, config.password, deviceName)
+ spotify.session, err = librespot.Login(config.Username, config.Password, deviceName)
if err != nil {
return nil, err
}