diff options
author | simon <simon@c200.home> | 2022-12-05 16:40:15 +0100 |
---|---|---|
committer | simon <simon@c200.home> | 2022-12-05 16:40:15 +0100 |
commit | 8bcd996e28572f2362d186c6e2bbb3971462feee (patch) | |
tree | 56711e91f7d694b1dc28c2574f4140fd2a8a346f | |
download | termsonic-8bcd996e28572f2362d186c6e2bbb3971462feee.tar.gz termsonic-8bcd996e28572f2362d186c6e2bbb3971462feee.zip |
Initial commit
-rw-r--r-- | go.mod | 16 | ||||
-rw-r--r-- | go.sum | 26 | ||||
-rw-r--r-- | main.go | 112 |
3 files changed, 154 insertions, 0 deletions
@@ -0,0 +1,16 @@ | |||
1 | module git.sixfoisneuf.fr/simon/termsonic | ||
2 | |||
3 | go 1.19 | ||
4 | |||
5 | require ( | ||
6 | github.com/delucks/go-subsonic v0.0.0-20220915164742-2744002c4be5 // indirect | ||
7 | github.com/gdamore/encoding v1.0.0 // indirect | ||
8 | github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 // indirect | ||
9 | github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||
10 | github.com/mattn/go-runewidth v0.0.13 // indirect | ||
11 | github.com/rivo/tview v0.0.0-20221128165837-db36428c92d9 // indirect | ||
12 | github.com/rivo/uniseg v0.4.2 // indirect | ||
13 | golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect | ||
14 | golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect | ||
15 | golang.org/x/text v0.3.7 // indirect | ||
16 | ) | ||
@@ -0,0 +1,26 @@ | |||
1 | github.com/delucks/go-subsonic v0.0.0-20220915164742-2744002c4be5 h1:RuuxidatioSKGOiBzL1mTY4X22DQD8weEbS3iRLHnAg= | ||
2 | github.com/delucks/go-subsonic v0.0.0-20220915164742-2744002c4be5/go.mod h1:vnbEuj6Z20PLcHB4rrLQAOXGMjtULfMGhRVSFPcSdUo= | ||
3 | github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= | ||
4 | github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= | ||
5 | github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 h1:QqwPZCwh/k1uYqq6uXSb9TRDhTkfQbO80v8zhnIe5zM= | ||
6 | github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04= | ||
7 | github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= | ||
8 | github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= | ||
9 | github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= | ||
10 | github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= | ||
11 | github.com/rivo/tview v0.0.0-20221128165837-db36428c92d9 h1:ccTgRxA37ypj3q8zB8G4k3xGPfBbIaMwrf3Yw6k50NY= | ||
12 | github.com/rivo/tview v0.0.0-20221128165837-db36428c92d9/go.mod h1:YX2wUZOcJGOIycErz2s9KvDaP0jnWwRCirQMPLPpQ+Y= | ||
13 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | ||
14 | github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8= | ||
15 | github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= | ||
16 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
17 | golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY= | ||
18 | golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
19 | golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
20 | golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= | ||
21 | golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
22 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
23 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
24 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= | ||
25 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||
26 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
@@ -0,0 +1,112 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "net/http" | ||
6 | "os" | ||
7 | |||
8 | "github.com/delucks/go-subsonic" | ||
9 | "github.com/rivo/tview" | ||
10 | ) | ||
11 | |||
12 | var ( | ||
13 | url = "" | ||
14 | username = "" | ||
15 | password = "" | ||
16 | |||
17 | sub *subsonic.Client = nil | ||
18 | |||
19 | // GUI | ||
20 | app *tview.Application | ||
21 | pages *tview.Pages | ||
22 | ) | ||
23 | |||
24 | func main() { | ||
25 | loadConfig() | ||
26 | |||
27 | app = tview.NewApplication() | ||
28 | |||
29 | pages = tview.NewPages() | ||
30 | |||
31 | showConfig := sub == nil | ||
32 | pages.AddPage("page-config", configPage(), true, showConfig) | ||
33 | |||
34 | if !showConfig { | ||
35 | pages.AddPage("page-main", mainView(), true, true) | ||
36 | } | ||
37 | |||
38 | if err := app.SetRoot(pages, true).EnableMouse(true).SetFocus(pages).Run(); err != nil { | ||
39 | fmt.Printf("Error running TermSonic: %v", err) | ||
40 | os.Exit(1) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | func configPage() *tview.Form { | ||
45 | form := tview.NewForm(). | ||
46 | AddInputField("Server URL", url, 40, nil, func(txt string) { url = txt }). | ||
47 | AddInputField("Username", username, 20, nil, func(txt string) { username = txt }). | ||
48 | AddPasswordField("Password", password, 20, '*', func(txt string) { password = txt }). | ||
49 | AddButton("Test", func() { | ||
50 | tmpSub := &subsonic.Client{ | ||
51 | Client: http.DefaultClient, | ||
52 | BaseUrl: url, | ||
53 | User: username, | ||
54 | ClientName: "termsonic", | ||
55 | PasswordAuth: true, | ||
56 | } | ||
57 | |||
58 | if err := tmpSub.Authenticate(password); err != nil { | ||
59 | alert("Could not auth: %v", err) | ||
60 | } else { | ||
61 | sub = tmpSub | ||
62 | |||
63 | alert("Success.") | ||
64 | } | ||
65 | }). | ||
66 | AddButton("Save", nil) | ||
67 | return form | ||
68 | } | ||
69 | |||
70 | func mainView() *tview.Grid { | ||
71 | grid := tview.NewGrid(). | ||
72 | SetRows(2, 0). | ||
73 | SetColumns(30, 0). | ||
74 | SetBorders(true) | ||
75 | |||
76 | grid.AddItem(tview.NewTextView().SetText("Artist & Album list"), 1, 0, 1, 1, 0, 0, true) | ||
77 | grid.AddItem(tview.NewTextView().SetText("Song list!"), 1, 1, 1, 2, 0, 0, false) | ||
78 | |||
79 | return grid | ||
80 | } | ||
81 | |||
82 | func alert(format string, params ...interface{}) { | ||
83 | modal := tview.NewModal(). | ||
84 | SetText(fmt.Sprintf(format, params...)). | ||
85 | AddButtons([]string{"OK"}). | ||
86 | SetDoneFunc(func(_ int, _ string) { | ||
87 | pages.RemovePage("alert") | ||
88 | }) | ||
89 | |||
90 | pages.AddPage("alert", modal, true, true) | ||
91 | } | ||
92 | |||
93 | func loadConfig() { | ||
94 | url = "http://music.nuc.local" | ||
95 | username = "admin" | ||
96 | password = "admin" | ||
97 | |||
98 | sub = &subsonic.Client{ | ||
99 | Client: http.DefaultClient, | ||
100 | User: username, | ||
101 | BaseUrl: url, | ||
102 | ClientName: "termsonic", | ||
103 | PasswordAuth: true, | ||
104 | } | ||
105 | |||
106 | if err := sub.Authenticate(password); err != nil { | ||
107 | sub = nil | ||
108 | } | ||
109 | } | ||
110 | |||
111 | func saveConfig() { | ||
112 | } | ||