forked from spicetify/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spicetify.go
420 lines (342 loc) · 11.2 KB
/
spicetify.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"runtime"
"github.com/khanhas/spicetify-cli/src/cmd"
"github.com/khanhas/spicetify-cli/src/utils"
colorable "github.com/mattn/go-colorable"
)
var (
version string
)
var (
flags = []string{}
commands = []string{}
quiet = false
extensionFocus = false
appFocus = false
noRestart = false
liveUpdate = false
)
func init() {
if runtime.GOOS != "windows" &&
runtime.GOOS != "darwin" &&
runtime.GOOS != "linux" {
utils.PrintError("Unsupported OS.")
os.Exit(1)
}
if version == "" {
version = "Dev"
}
log.SetFlags(0)
// Supports print color output for Windows
log.SetOutput(colorable.NewColorableStdout())
// Separates flags and commands
for _, v := range os.Args[1:] {
if v[0] == '-' && v != "-1" {
if v[1] != '-' && len(v) > 2 {
for _, char := range v[1:] {
flags = append(flags, "-"+string(char))
}
} else {
flags = append(flags, v)
}
} else {
commands = append(commands, v)
}
}
for _, v := range flags {
switch v {
case "-c", "--config":
fmt.Println(cmd.GetConfigPath())
os.Exit(0)
case "-h", "--help":
kind := ""
if len(commands) > 0 {
kind = commands[0]
}
if kind == "config" {
helpConfig()
} else {
help()
}
os.Exit(0)
case "-v", "--version":
fmt.Println(version)
os.Exit(0)
case "-e", "--extension":
extensionFocus = true
case "-a", "--app":
appFocus = true
case "-q", "--quiet":
quiet = true
case "-n", "--no-restart":
noRestart = true
case "-l", "--live-update":
liveUpdate = true
}
}
if quiet {
log.SetOutput(ioutil.Discard)
os.Stdout = nil
}
cmd.InitConfig(quiet)
if len(commands) < 1 {
utils.PrintInfo(`Run "spicetify -h" for commands list.`)
os.Exit(0)
}
}
func main() {
// Non-chainable commands
switch commands[0] {
case "config":
commands = commands[1:]
if len(commands) == 0 {
cmd.DisplayAllConfig()
} else if len(commands) == 1 {
cmd.DisplayConfig(commands[0])
} else {
cmd.EditConfig(commands)
}
return
case "color":
commands = commands[1:]
if len(commands) == 0 {
cmd.DisplayColors()
} else {
cmd.EditColor(commands)
}
return
case "path":
commands = commands[1:]
path, err := (func() (string, error) {
if extensionFocus {
if len(commands) == 0 {
return cmd.ExtensionAllPath()
}
return cmd.ExtensionPath(commands[0])
} else if appFocus {
if len(commands) == 0 {
return cmd.AppAllPath()
}
return cmd.AppPath(commands[0])
} else {
if len(commands) == 0 {
return cmd.ThemeAllAssetsPath()
}
return cmd.ThemeAssetPath(commands[0])
}
})()
if err != nil {
utils.Fatal(err)
}
log.Println(path)
return
case "upgrade":
cmd.Upgrade(version)
return
}
utils.PrintBold("spicetify v" + version)
cmd.CheckUpgrade(version)
cmd.InitPaths()
// Unchainable commands
switch commands[0] {
case "watch":
var name []string
if len(commands) > 1 {
name = commands[1:]
}
if extensionFocus {
cmd.WatchExtensions(name, liveUpdate)
} else if appFocus {
cmd.WatchCustomApp(name, liveUpdate)
} else {
cmd.Watch(liveUpdate)
}
return
}
// Chainable commands
for _, v := range commands {
switch v {
case "backup":
cmd.Backup(version)
case "clear":
cmd.Clear()
case "apply":
cmd.Apply(version)
restartSpotify()
case "update":
if extensionFocus {
cmd.UpdateAllExtension()
} else {
cmd.UpdateTheme()
}
case "restore":
cmd.Restore()
restartSpotify()
case "enable-devtool":
cmd.SetDevTool(true)
restartSpotify()
case "disable-devtool":
cmd.SetDevTool(false)
restartSpotify()
case "restart":
cmd.RestartSpotify()
case "auto":
cmd.Auto(version)
restartSpotify()
default:
utils.PrintError(`Command "` + v + `" not found.`)
utils.PrintInfo(`Run "spicetify -h" for list of valid commands.`)
os.Exit(1)
}
}
}
func restartSpotify() {
if !noRestart {
cmd.RestartSpotify()
}
}
func help() {
utils.PrintBold("spicetify v" + version)
log.Println(utils.Bold("USAGE") + "\n" +
"spicetify [-q] [-e] [-a] \x1B[4mcommand\033[0m...\n" +
"spicetify {-c | --config} | {-v | --version} | {-h | --help}\n\n" +
utils.Bold("DESCRIPTION") + "\n" +
"Customize Spotify client UI and functionality\n\n" +
utils.Bold("CHAINABLE COMMANDS") + `
backup Start backup and preprocessing app files.
apply Apply customization.
update On default, update theme CSS and colors.
Use with flag "-e" to update extensions.
restore Restore Spotify to original state.
clear Clear current backup files.
enable-devtool Enable Spotify's developer tools.
Hit Ctrl + Shift + I in the client to start using.
disable-devtool Disable Spotify's developer tools.
watch Enter watch mode.
On default, update CSS on color.ini or user.css's changes.
Use with flag "-e" to update extensions on changes.
restart Restart Spotify client.
` + utils.Bold("NON-CHAINABLE COMMANDS") + `
path Print path of color, css, extension file or
custom app directory and quit.
1. Print all theme's assets:
spicetify path
2. Print theme's color.ini path:
spicetify path color
3. Print theme's user.css path:
spicetify path css
4. Print theme's assets path:
spicetify path assets
5. Print all extensions path:
spicetify -e path
6. Print extension <name> path:
spicetify -e path <name>
7. Print all custom apps path:
spicetify -a path
8. Print custom app <name> path:
spicetify -a path <name>
config 1. Print all config fields and values:
spicetify config
2. Print one config field's value:
spicetify config <field>
Example usage:
spicetify config color_scheme
spicetify config custom_apps
3. Change value of one or multiple config fields.
spicetify config <field> <value> [<field> <value> ...]
"extensions" and "custom_apps" fields are arrays of values,
so <value> will be appended to those fields' current value.
To remove one of array's values, postfix "-" to <value>.
Example usage:
- Enable "disable_sentry" preprocess:
spicetify config disable_sentry 1
- Add extension "myFakeExt.js" to current extensions list:
spicetify config extensions myFakeExt.js
- Remove extension "wrongname.js" from extensions list:
spicetify config extensions wrongname.js-
- Disable "inject_css" and enable "song_page"
spicetify config inject_css 0 song_page 1
color 1. Print all color fields and values.
spicetify color
Color boxes require 24-bit color (True color) supported
terminal to show colors correctly.
2. Change theme's one or multiple color values.
spicetify color <field> <value> [<field> <value> ...]
<value> can be in hex or decimal (rrr,ggg,bbb) format.
Example usage:
- Change main_bg to ff0000
spicetify color main_bg ff0000
- Change slider_bg to 00ff00 and pressing_fg to 0000ff
spicetify color slider_bg 00ff00 pressing_fg 0000ff
upgrade Upgrade spicetify latest version
` + utils.Bold("FLAGS") + `
-q, --quiet Quiet mode (no output). Be careful, dangerous operations
like clear backup, restore will proceed without prompting
permission.
-e, --extension Use with "update", "watch" or "path" command to
focus on extensions.
-a, --app Use with "path" to focus on custom apps.
-n, --no-restart Do not restart Spotify after running command(s), except
"restart" command.
-l, --live-update Use with "watch" command to auto-reload Spotify on change
-c, --config Print config file path and quit
-h, --help Print this help text and quit
-v, --version Print version number and quit
For config information, run "spicetify -h config".
For more information and bug report: https://github.com/khanhas/spicetify-cli/`)
}
func helpConfig() {
utils.PrintBold("CONFIG MEANING")
log.Println(utils.Bold("[Setting]") + `
spotify_path
Path to Spotify directory
prefs_path
Path to Spotify's "prefs" file
current_theme
Name of folder of your theme
color_scheme
Color config section name in color.ini file.
If color_scheme is blank, first section in color.ini file would be used.
inject_css <0 | 1>
Whether custom css from user.css in theme folder is applied
replace_colors <0 | 1>
Whether custom colors is applied
spotify_launch_flags
Command-line flags used when launching/restarting Spotify.
Separate each flag with "|".
List of valid flags: https://github.com/khanhas/spicetify-cli/wiki/Spotify-Commandline-Flags
` + utils.Bold("[Preprocesses]") + `
disable_sentry <0 | 1>
Prevents Sentry and Amazon Qualaroo to send console log/error/warning to Spotify developers.
Enable if you don't want to catch their attention when developing extension or app.
disable_ui_logging <0 | 1>
Various elements logs every user clicks, scrolls.
Enable to stop logging and improve user experience.
remove_rtl_rule <0 | 1>
To support Arabic and other Right-To-Left language, Spotify added a lot of
CSS rules that are obsoleted to Left-To-Right users.
Enable to remove all of them and improve render speed.
expose_apis <0 | 1>
Leaks some Spotify's API, functions, objects to Spicetify global object that
are useful for making extensions to extend Spotify functionality.
disable_upgrade_check <0 | 1>
Prevent Spotify checking new version and visually notifying user.
[Windows] Note: Automatic update still works if you don't manually delete "SpotifyMigrator.exe" and "SpotifyUpdate.exe".
` + utils.Bold("[AdditionalOptions]") + `
custom_apps <string>
List of custom apps. Separate each app with "|".
extensions <string>
List of Javascript files to be executed along with Spotify main script.
Separate each extension with "|".
home_config <0 | 1>
Enable ability to re-arrange sections in Home page.
Navigate to Home page, turn "Home config" mode on in Profile menu and hover on sections to show customization buttons.
sidebar_config <0 | 1>
Enable ability to stick, hide, re-arrange sidebar items.
Turn "Sidebar config" mode on in Profile menu and hover on sidebar items to show customization buttons.`)
}