-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
121 lines (109 loc) · 2.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"flag"
"log"
"spot/menus"
"spot/setup"
"spot/spotify"
)
func skipForcedSetup(action string) bool {
return spotify.IsDataSet(spotify.ClientId) &&
spotify.IsDataSet(spotify.ClientSecret) &&
(action == "server" || (spotify.IsDataSet(spotify.Token) || action == "auth"))
}
func main() {
actionPtr := flag.String("action", "", "action to take")
artistPtr := flag.String("artist", "", "artist to focus")
albumPtr := flag.String("album", "", "album to focus")
trackPtr := flag.String("track", "", "track to play")
contextPtr := flag.String("context", "", "context to use for track to play")
flag.Parse()
args := flag.Args()
if !skipForcedSetup(*actionPtr) {
err := setup.Creds(args)
if err != nil {
log.Fatal(err)
return
}
return
}
if *actionPtr != "" {
action := *actionPtr
if action == "playtrack" {
err := spotify.PlayTrack(*trackPtr, *contextPtr)
if err != nil {
log.Fatal(err)
return
}
} else if action == "revealinspotify" {
err := spotify.Reveal(*contextPtr)
if err != nil {
log.Fatal(err)
return
}
} else if action == "auth" {
err := setup.LaunchAuth()
if err != nil {
log.Fatal(err)
return
}
} else if action == "server" {
err := setup.Server()
if err != nil {
log.Fatal(err)
return
}
} else {
err := spotify.ApplyControl(action)
if err != nil {
log.Fatal(err)
return
}
}
return
}
if *albumPtr != "" {
err := menus.AlbumDetailMenu(*albumPtr, args)
if err != nil {
log.Fatal(err)
}
return
}
if *artistPtr != "" {
err := menus.ArtistDetailMenu(*artistPtr, args)
if err != nil {
log.Fatal(err)
}
return
}
spotifyStatus, err := spotify.GetStatus()
if err != nil {
log.Fatal(err)
return
}
if len(args) > 0 && (args[0] == "c") {
err = menus.ControlsMenu(spotifyStatus)
if err != nil {
log.Fatal(err)
return
}
} else if len(args) > 0 && (args[0] == "auth") {
err = menus.SetupAuthMenu()
if err != nil {
log.Fatal(err)
return
}
} else if len(args) > 0 {
err = menus.SearchMenu(args)
if err != nil {
log.Fatal(err)
return
}
} else {
err = menus.StatusMenu(spotifyStatus)
if err != nil {
log.Fatal(err)
return
}
}
}