1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-400 SpotifyWeb extracted to new config format

This commit is contained in:
Chris Cummer 2019-04-16 02:54:10 -07:00
parent ae081e4b9f
commit b4868a54e6
3 changed files with 44 additions and 25 deletions

View File

@ -280,7 +280,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
settings := spotify.NewSettingsFromYAML(wtf.Config)
widget = spotify.NewWidget(app, pages, settings)
case "spotifyweb":
widget = spotifyweb.NewWidget(app, pages)
settings := spotifyweb.NewSettingsFromYAML(wtf.Config)
widget = spotifyweb.NewWidget(app, pages, settings)
case "status":
widget = status.NewWidget(app)
case "system":

View File

@ -0,0 +1,30 @@
package spotifyweb
import (
"os"
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
)
type Settings struct {
common *cfg.Common
callbackPort string
clientID string
secretKey string
}
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
localConfig, _ := ymlConfig.Get("wtf.mods.spotifyweb")
settings := Settings{
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
callbackPort: localConfig.UString("callbackPort", "8080"),
clientID: localConfig.UString("clientID", os.Getenv("SPOTIFY_ID")),
secretKey: localConfig.UString("secretKey", os.Getenv("SPOTIFY_SECRET")),
}
return &settings
}

View File

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"net/http"
"os"
"time"
"github.com/gdamore/tcell"
@ -47,10 +46,12 @@ type Info struct {
type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget
Info
clientChan chan *spotify.Client
client *spotify.Client
clientChan chan *spotify.Client
playerState *spotify.PlayerState
settings *Settings
}
var (
@ -79,27 +80,12 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
tempClientChan <- &client
}
func clientID() string {
return wtf.Config.UString(
"wtf.mods.spotifyweb.clientID",
os.Getenv("SPOTIFY_ID"),
)
}
func secretKey() string {
return wtf.Config.UString(
"wtf.mods.spotifyweb.secretKey",
os.Getenv("SPOTIFY_SECRET"),
)
}
// NewWidget creates a new widget for WTF
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
callbackPort = wtf.Config.UString("wtf.mods.spotifyweb.callbackPort", "8080")
redirectURI = "http://localhost:" + callbackPort + "/callback"
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
redirectURI = "http://localhost:" + settings.callbackPort + "/callback"
auth = spotify.NewAuthenticator(redirectURI, spotify.ScopeUserReadCurrentlyPlaying, spotify.ScopeUserReadPlaybackState, spotify.ScopeUserModifyPlaybackState)
auth.SetAuthInfo(clientID(), secretKey())
auth.SetAuthInfo(settings.clientID, settings.secretKey)
authURL = auth.AuthURL(state)
var client *spotify.Client
@ -108,10 +94,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
widget := Widget{
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget(app, "SpotifyWeb", "spotifyweb", true),
Info: Info{},
clientChan: tempClientChan,
client: client,
playerState: playerState,
Info: Info{},
client: client,
clientChan: tempClientChan,
playerState: playerState,
settings: settings,
}
http.HandleFunc("/callback", authHandler)