port and xdg open
This commit is contained in:
parent
25e19cfe4f
commit
b3b33733b0
13
README.md
13
README.md
@ -25,9 +25,18 @@ then
|
||||
to use add your information to ~/.config/gospt/client.yml like this
|
||||
|
||||
```
|
||||
client_id: ID
|
||||
client_secret: SECRET
|
||||
client_id: "idgoeshere"
|
||||
client_secret: "secretgoeshere"
|
||||
port: "8888"
|
||||
```
|
||||
if you dont want to store your secret in the file in plaintext you can use a command to retreive it:
|
||||
|
||||
```
|
||||
client_secret_cmd: "secret spotify_secret"
|
||||
```
|
||||
|
||||
you should have either client_secret or client_secret_cmd
|
||||
|
||||
|
||||
then run
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"gospt/internal/config"
|
||||
@ -25,17 +26,17 @@ var (
|
||||
)
|
||||
|
||||
func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
||||
if config.Values.ClientId == "" || config.Values.ClientSecret == "" {
|
||||
if config.Values.ClientId == "" || config.Values.ClientSecret == "" || config.Values.Port == "" {
|
||||
configDir, _ := os.UserConfigDir()
|
||||
fmt.Println("PLEASE WRITE YOUR CONFIG FILE IN", filepath.Join(configDir, "gospt/client.yml"))
|
||||
fmt.Println("GO HERE TO AND MAKE AN APPLICATION: https://developer.spotify.com/dashboard/applications")
|
||||
fmt.Println("\nclient_id: \"idgoesherelikethis\"\nclient_secret: \"secretgoesherelikethis\"")
|
||||
fmt.Print("\nclient_id: \"idgoesherelikethis\"\nclient_secret: \"secretgoesherelikethis\"\nport:\"8888\"\n\n")
|
||||
return nil, fmt.Errorf("\nINVALID CONFIG")
|
||||
}
|
||||
auth = spotifyauth.New(
|
||||
spotifyauth.WithClientID(config.Values.ClientId),
|
||||
spotifyauth.WithClientSecret(config.Values.ClientSecret),
|
||||
spotifyauth.WithRedirectURL("http://localhost:1024/callback"),
|
||||
spotifyauth.WithRedirectURL(fmt.Sprintf("http://localhost:%s/callback", config.Values.Port)),
|
||||
spotifyauth.WithScopes(
|
||||
spotifyauth.ScopeImageUpload,
|
||||
spotifyauth.ScopePlaylistReadPrivate,
|
||||
@ -102,14 +103,15 @@ func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
||||
log.Println("Got request for:", r.URL.String())
|
||||
})
|
||||
go func() {
|
||||
err := http.ListenAndServe(":1024", nil)
|
||||
err := http.ListenAndServe(fmt.Sprintf(":%s", config.Values.Port), nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
url := auth.AuthURL(state)
|
||||
fmt.Println("GO HERE", url)
|
||||
|
||||
fmt.Println(url)
|
||||
cmd := exec.Command("xdg-open", url)
|
||||
cmd.Start()
|
||||
// wait for auth to complete
|
||||
client := <-ch
|
||||
|
||||
|
@ -4,4 +4,5 @@ var Values struct {
|
||||
ClientId string `yaml:"client_id"`
|
||||
ClientSecret string `yaml:"client_secret"`
|
||||
ClientSecretCmd string `yaml:"client_secret_cmd"`
|
||||
Port string `yaml:"port"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user