aboutsummaryrefslogtreecommitdiff
path: root/spotify.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-05-21 20:05:01 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-05-21 20:05:01 +0200
commit5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06 (patch)
tree5268e39568e6146521e4be9e0c1b70d3afca538c /spotify.go
parentead811a4ebd0074cc4d42da53daacbb358229fac (diff)
downloadWRMS-5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06.tar.gz
WRMS-5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06.zip
implement YAML config and admin connections
Diffstat (limited to 'spotify.go')
-rw-r--r--spotify.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/spotify.go b/spotify.go
index 8a32fc6..0e4974a 100644
--- a/spotify.go
+++ b/spotify.go
@@ -25,23 +25,30 @@ const (
deviceName = "wrms"
)
+type spotifyConfig struct {
+ username string
+ password string
+}
+
type SpotifyBackend struct {
session *core.Session
}
-func NewSpotify() (*SpotifyBackend, error) {
+func NewSpotify(config *spotifyConfig) (*SpotifyBackend, error) {
spotify := SpotifyBackend{}
+ if config != nil {
+ config = &spotifyConfig{}
+ }
- var err error
+ config.username = os.Getenv("WRMS_SPOTIFY_USER")
+ config.password = os.Getenv("WRMS_SPOTIFY_PASSWORD")
- username := os.Getenv("WRMS_SPOTIFY_USER")
- password := os.Getenv("WRMS_SPOTIFY_PASSWORD")
- if username == "" || password == "" {
+ if config.username == "" || config.password == "" {
return nil, errors.New("User and password for spotify must be provided")
}
- spotify.session, err = librespot.Login(username, password, deviceName)
-
+ var err error
+ spotify.session, err = librespot.Login(config.username, config.password, deviceName)
if err != nil {
return nil, err
}