-
Notifications
You must be signed in to change notification settings - Fork 94
/
netease.go
62 lines (52 loc) · 1.74 KB
/
netease.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
package commands
import (
"net/http"
_ "net/http/pprof"
"strconv"
"github.com/anhoder/foxful-cli/model"
"github.com/gookit/gcli/v2"
"github.com/mattn/go-runewidth"
"github.com/go-musicfox/go-musicfox/internal/configs"
"github.com/go-musicfox/go-musicfox/internal/types"
"github.com/go-musicfox/go-musicfox/internal/ui"
"github.com/go-musicfox/go-musicfox/utils"
)
func NewPlayerCommand() *gcli.Command {
cmd := &gcli.Command{
Name: "netease",
UseFor: "Command line player for Netease Cloud Music",
Func: runPlayer,
}
return cmd
}
func runPlayer(_ *gcli.Command, _ []string) error {
if GlobalOptions.PProfMode {
utils.Go(func() {
panic(http.ListenAndServe(":"+strconv.Itoa(configs.ConfigRegistry.Main.PProfPort), nil))
}, true)
}
http.DefaultClient.Timeout = types.AppHttpTimeout
runewidth.DefaultCondition.EastAsianWidth = false
opts := model.DefaultOptions()
configs.ConfigRegistry.FillToModelOpts(opts)
model.Submit = types.SubmitText
model.SearchPlaceholder = types.SearchPlaceholder
model.SearchResult = types.SearchResult
var (
netease = ui.NewNetease(model.NewApp(opts))
eventHandler = ui.NewEventHandler(netease)
)
eventHandler.RegisterGlobalHotkeys(opts)
netease.With(
model.WithHook(netease.InitHook, netease.CloseHook),
model.WithMainMenu(ui.NewMainMenu(netease), &model.MenuItem{Title: "网易云音乐"}),
func(options *model.Options) {
options.LocalSearchMenu = ui.NewLocalSearchMenu(netease)
options.Components = append(options.Components, netease.Player())
options.KBControllers = append(options.KBControllers, eventHandler)
options.MouseControllers = append(options.MouseControllers, eventHandler)
options.Ticker = netease.Player().RenderTicker()
},
)
return netease.Run()
}