File tree 1 file changed +25
-2
lines changed
1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change 8
8
"log"
9
9
"net/http"
10
10
"os"
11
+ "os/exec"
11
12
"path/filepath"
13
+ "runtime"
12
14
13
15
_auth "github.com/zmb3/spotify/v2/auth"
14
16
"golang.org/x/oauth2"
@@ -17,6 +19,24 @@ import (
17
19
"github.com/zmb3/spotify/v2"
18
20
)
19
21
22
+ // Taken from: https://gist.github.com/hyg/9c4afcd91fe24316cbf0l
23
+ func openbrowser (url string ) error {
24
+ var err error
25
+
26
+ switch runtime .GOOS {
27
+ case "linux" :
28
+ err = exec .Command ("xdg-open" , url ).Start ()
29
+ case "windows" :
30
+ err = exec .Command ("rundll32" , "url.dll,FileProtocolHandler" , url ).Start ()
31
+ case "darwin" :
32
+ err = exec .Command ("open" , url ).Start ()
33
+ default :
34
+ err = fmt .Errorf ("unsupported platform" )
35
+ }
36
+
37
+ return err
38
+ }
39
+
20
40
var (
21
41
redirectURI = "http://localhost:8080/callback"
22
42
scopes = []string {
@@ -85,8 +105,11 @@ func InitClient() error {
85
105
}()
86
106
url := auth .AuthURL (state )
87
107
88
- fmt .Println ("Please log in to Spotify by visiting the following page in your browser: " )
89
- fmt .Println (url )
108
+ fmt .Println ("Please log in to Spotify through the browser." )
109
+ if err := openbrowser (url ); err != nil {
110
+ fmt .Printf ("Error opening the default browsers: %s\n Please open the following link Manually:\n " , err .Error ())
111
+ fmt .Println (url )
112
+ }
90
113
91
114
// wait for auth to complete
92
115
payload := <- ch
You can’t perform that action at this time.
0 commit comments