From 8bcd996e28572f2362d186c6e2bbb3971462feee Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 5 Dec 2022 16:40:15 +0100 Subject: Initial commit --- go.mod | 16 ++++++++++ go.sum | 26 +++++++++++++++ main.go | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d1241d5 --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module git.sixfoisneuf.fr/simon/termsonic + +go 1.19 + +require ( + github.com/delucks/go-subsonic v0.0.0-20220915164742-2744002c4be5 // indirect + github.com/gdamore/encoding v1.0.0 // indirect + github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/rivo/tview v0.0.0-20221128165837-db36428c92d9 // indirect + github.com/rivo/uniseg v0.4.2 // indirect + golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect + golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect + golang.org/x/text v0.3.7 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..396fa5d --- /dev/null +++ b/go.sum @@ -0,0 +1,26 @@ +github.com/delucks/go-subsonic v0.0.0-20220915164742-2744002c4be5 h1:RuuxidatioSKGOiBzL1mTY4X22DQD8weEbS3iRLHnAg= +github.com/delucks/go-subsonic v0.0.0-20220915164742-2744002c4be5/go.mod h1:vnbEuj6Z20PLcHB4rrLQAOXGMjtULfMGhRVSFPcSdUo= +github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= +github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= +github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 h1:QqwPZCwh/k1uYqq6uXSb9TRDhTkfQbO80v8zhnIe5zM= +github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/rivo/tview v0.0.0-20221128165837-db36428c92d9 h1:ccTgRxA37ypj3q8zB8G4k3xGPfBbIaMwrf3Yw6k50NY= +github.com/rivo/tview v0.0.0-20221128165837-db36428c92d9/go.mod h1:YX2wUZOcJGOIycErz2s9KvDaP0jnWwRCirQMPLPpQ+Y= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8= +github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY= +golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/main.go b/main.go new file mode 100644 index 0000000..ad0d7c8 --- /dev/null +++ b/main.go @@ -0,0 +1,112 @@ +package main + +import ( + "fmt" + "net/http" + "os" + + "github.com/delucks/go-subsonic" + "github.com/rivo/tview" +) + +var ( + url = "" + username = "" + password = "" + + sub *subsonic.Client = nil + + // GUI + app *tview.Application + pages *tview.Pages +) + +func main() { + loadConfig() + + app = tview.NewApplication() + + pages = tview.NewPages() + + showConfig := sub == nil + pages.AddPage("page-config", configPage(), true, showConfig) + + if !showConfig { + pages.AddPage("page-main", mainView(), true, true) + } + + if err := app.SetRoot(pages, true).EnableMouse(true).SetFocus(pages).Run(); err != nil { + fmt.Printf("Error running TermSonic: %v", err) + os.Exit(1) + } +} + +func configPage() *tview.Form { + form := tview.NewForm(). + AddInputField("Server URL", url, 40, nil, func(txt string) { url = txt }). + AddInputField("Username", username, 20, nil, func(txt string) { username = txt }). + AddPasswordField("Password", password, 20, '*', func(txt string) { password = txt }). + AddButton("Test", func() { + tmpSub := &subsonic.Client{ + Client: http.DefaultClient, + BaseUrl: url, + User: username, + ClientName: "termsonic", + PasswordAuth: true, + } + + if err := tmpSub.Authenticate(password); err != nil { + alert("Could not auth: %v", err) + } else { + sub = tmpSub + + alert("Success.") + } + }). + AddButton("Save", nil) + return form +} + +func mainView() *tview.Grid { + grid := tview.NewGrid(). + SetRows(2, 0). + SetColumns(30, 0). + SetBorders(true) + + grid.AddItem(tview.NewTextView().SetText("Artist & Album list"), 1, 0, 1, 1, 0, 0, true) + grid.AddItem(tview.NewTextView().SetText("Song list!"), 1, 1, 1, 2, 0, 0, false) + + return grid +} + +func alert(format string, params ...interface{}) { + modal := tview.NewModal(). + SetText(fmt.Sprintf(format, params...)). + AddButtons([]string{"OK"}). + SetDoneFunc(func(_ int, _ string) { + pages.RemovePage("alert") + }) + + pages.AddPage("alert", modal, true, true) +} + +func loadConfig() { + url = "http://music.nuc.local" + username = "admin" + password = "admin" + + sub = &subsonic.Client{ + Client: http.DefaultClient, + User: username, + BaseUrl: url, + ClientName: "termsonic", + PasswordAuth: true, + } + + if err := sub.Authenticate(password); err != nil { + sub = nil + } +} + +func saveConfig() { +} -- cgit v1.2.3