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:
parent
ae081e4b9f
commit
b4868a54e6
3
main.go
3
main.go
@ -280,7 +280,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
settings := spotify.NewSettingsFromYAML(wtf.Config)
|
settings := spotify.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = spotify.NewWidget(app, pages, settings)
|
widget = spotify.NewWidget(app, pages, settings)
|
||||||
case "spotifyweb":
|
case "spotifyweb":
|
||||||
widget = spotifyweb.NewWidget(app, pages)
|
settings := spotifyweb.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = spotifyweb.NewWidget(app, pages, settings)
|
||||||
case "status":
|
case "status":
|
||||||
widget = status.NewWidget(app)
|
widget = status.NewWidget(app)
|
||||||
case "system":
|
case "system":
|
||||||
|
30
modules/spotifyweb/settings.go
Normal file
30
modules/spotifyweb/settings.go
Normal 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
|
||||||
|
}
|
@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
@ -47,10 +46,12 @@ type Info struct {
|
|||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.HelpfulWidget
|
wtf.HelpfulWidget
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
Info
|
Info
|
||||||
clientChan chan *spotify.Client
|
|
||||||
client *spotify.Client
|
client *spotify.Client
|
||||||
|
clientChan chan *spotify.Client
|
||||||
playerState *spotify.PlayerState
|
playerState *spotify.PlayerState
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -79,27 +80,12 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
tempClientChan <- &client
|
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
|
// NewWidget creates a new widget for WTF
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
callbackPort = wtf.Config.UString("wtf.mods.spotifyweb.callbackPort", "8080")
|
redirectURI = "http://localhost:" + settings.callbackPort + "/callback"
|
||||||
redirectURI = "http://localhost:" + callbackPort + "/callback"
|
|
||||||
|
|
||||||
auth = spotify.NewAuthenticator(redirectURI, spotify.ScopeUserReadCurrentlyPlaying, spotify.ScopeUserReadPlaybackState, spotify.ScopeUserModifyPlaybackState)
|
auth = spotify.NewAuthenticator(redirectURI, spotify.ScopeUserReadCurrentlyPlaying, spotify.ScopeUserReadPlaybackState, spotify.ScopeUserModifyPlaybackState)
|
||||||
auth.SetAuthInfo(clientID(), secretKey())
|
auth.SetAuthInfo(settings.clientID, settings.secretKey)
|
||||||
authURL = auth.AuthURL(state)
|
authURL = auth.AuthURL(state)
|
||||||
|
|
||||||
var client *spotify.Client
|
var client *spotify.Client
|
||||||
@ -108,10 +94,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, "SpotifyWeb", "spotifyweb", true),
|
TextWidget: wtf.NewTextWidget(app, "SpotifyWeb", "spotifyweb", true),
|
||||||
Info: Info{},
|
|
||||||
clientChan: tempClientChan,
|
Info: Info{},
|
||||||
client: client,
|
client: client,
|
||||||
playerState: playerState,
|
clientChan: tempClientChan,
|
||||||
|
playerState: playerState,
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
http.HandleFunc("/callback", authHandler)
|
http.HandleFunc("/callback", authHandler)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user