2021-10-09 05:51:47 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-10-18 00:42:10 -06:00
|
|
|
"strings"
|
|
|
|
|
2021-10-14 10:32:29 -06:00
|
|
|
"github.com/rivo/tview"
|
2021-10-09 05:51:47 -06:00
|
|
|
)
|
|
|
|
|
2021-10-18 00:42:10 -06:00
|
|
|
func getFormattedString(s string, width int) string {
|
|
|
|
if len(s) < width {
|
|
|
|
s += strings.Repeat(" ", (width - len(s)))
|
|
|
|
} else {
|
|
|
|
s = s[:(width - 2)]
|
|
|
|
s += " "
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
2021-10-17 10:12:02 -06:00
|
|
|
|
2021-11-12 23:02:00 -07:00
|
|
|
func togglePlayBack() error {
|
|
|
|
status, err := CONN.Status()
|
2021-10-17 10:12:02 -06:00
|
|
|
if status["state"] == "play" && err == nil {
|
2021-11-12 23:02:00 -07:00
|
|
|
CONN.Pause(true)
|
2021-10-17 10:12:02 -06:00
|
|
|
} else if status["state"] == "pause" && err == nil {
|
2021-11-12 23:02:00 -07:00
|
|
|
CONN.Play(-1)
|
2021-10-09 05:51:47 -06:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
2021-10-14 10:32:29 -06:00
|
|
|
|
2021-11-12 23:02:00 -07:00
|
|
|
func UpdatePlaylist(inputTable *tview.Table) {
|
|
|
|
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
|
2021-10-17 13:57:30 -06:00
|
|
|
|
2021-10-28 22:14:55 -06:00
|
|
|
inputTable.Clear()
|
2021-10-17 13:57:30 -06:00
|
|
|
for i, j := range _playlistAttr {
|
2021-10-28 22:14:55 -06:00
|
|
|
_, _, w, _ := inputTable.GetInnerRect()
|
2021-10-17 13:57:30 -06:00
|
|
|
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
|
2021-10-28 22:14:55 -06:00
|
|
|
inputTable.SetCell(i, 0, tview.NewTableCell(getFormattedString(j["file"], w/3)))
|
2021-10-17 13:57:30 -06:00
|
|
|
} else {
|
2021-10-28 22:14:55 -06:00
|
|
|
inputTable.SetCell(i, 0, tview.NewTableCell(getFormattedString("[green]"+j["Title"], w/3)))
|
|
|
|
inputTable.SetCell(i, 1, tview.NewTableCell(getFormattedString("[magenta]"+j["Artist"], w/3)))
|
|
|
|
inputTable.SetCell(i, 2, tview.NewTableCell("[yellow]"+j["Album"]))
|
2021-10-17 13:57:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 10:12:02 -06:00
|
|
|
func join(stringSlice []string) string {
|
2021-10-14 10:32:29 -06:00
|
|
|
var _s string = stringSlice[0]
|
2021-10-17 10:12:02 -06:00
|
|
|
for i := 1; i < len(stringSlice); i++ {
|
|
|
|
if _s != "" {
|
|
|
|
_s += ("/" + stringSlice[i])
|
2021-10-14 10:32:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return _s
|
|
|
|
}
|
|
|
|
|
2021-11-12 23:02:00 -07:00
|
|
|
func Update(f []FileNode, inputTable *tview.Table) {
|
2021-10-17 10:12:02 -06:00
|
|
|
inputTable.Clear()
|
|
|
|
for i, j := range f {
|
2021-10-14 10:32:29 -06:00
|
|
|
if len(j.children) == 0 {
|
2021-11-12 23:02:00 -07:00
|
|
|
_songAttributes, err := CONN.ListAllInfo(j.absolutePath)
|
2021-10-17 10:12:02 -06:00
|
|
|
if err == nil && _songAttributes[0]["Title"] != "" {
|
2021-10-18 00:42:10 -06:00
|
|
|
_, _, w, _ := inputTable.GetInnerRect()
|
2021-10-14 10:32:29 -06:00
|
|
|
inputTable.SetCell(i, 0,
|
2021-10-18 01:48:56 -06:00
|
|
|
tview.NewTableCell("[green]"+getFormattedString(_songAttributes[0]["Title"], w/3)).
|
2021-10-17 10:12:02 -06:00
|
|
|
SetAlign(tview.AlignLeft))
|
2021-10-14 10:32:29 -06:00
|
|
|
|
|
|
|
inputTable.SetCell(i, 1,
|
2021-10-18 01:48:56 -06:00
|
|
|
tview.NewTableCell("[magenta]"+getFormattedString(_songAttributes[0]["Artist"], w/3)).
|
2021-10-17 10:12:02 -06:00
|
|
|
SetAlign(tview.AlignLeft))
|
2021-10-14 10:32:29 -06:00
|
|
|
|
|
|
|
inputTable.SetCell(i, 2,
|
2021-10-18 01:48:56 -06:00
|
|
|
tview.NewTableCell("[yellow]"+_songAttributes[0]["Album"]).
|
2021-10-17 10:12:02 -06:00
|
|
|
SetAlign(tview.AlignLeft))
|
2021-10-14 10:32:29 -06:00
|
|
|
|
2021-10-17 10:12:02 -06:00
|
|
|
} else if _songAttributes[0]["Title"] == "" {
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
tview.NewTableCell("[blue]"+j.path).
|
|
|
|
SetAlign(tview.AlignLeft))
|
2021-10-14 10:32:29 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inputTable.SetCell(i, 0,
|
2021-10-18 01:48:56 -06:00
|
|
|
tview.NewTableCell("[yellow::b]"+j.path).
|
2021-10-17 10:12:02 -06:00
|
|
|
SetAlign(tview.AlignLeft))
|
2021-10-14 10:32:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|