2021-10-09 05:51:47 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/fhs/gompd/mpd"
|
2021-10-14 10:32:29 -06:00
|
|
|
// "github.com/gdamore/tcell/v2"
|
|
|
|
"github.com/rivo/tview"
|
|
|
|
// "fmt"
|
2021-10-09 05:51:47 -06:00
|
|
|
)
|
|
|
|
|
2021-10-17 10:12:02 -06:00
|
|
|
var directoryMap map[string][]int = make(map[string][]int)
|
|
|
|
|
2021-10-09 05:51:47 -06:00
|
|
|
func togglePlayBack(connection mpd.Client) error {
|
|
|
|
status, err := connection.Status()
|
2021-10-17 10:12:02 -06:00
|
|
|
if status["state"] == "play" && err == nil {
|
2021-10-09 05:51:47 -06:00
|
|
|
connection.Pause(true)
|
2021-10-17 10:12:02 -06:00
|
|
|
} else if status["state"] == "pause" && err == nil {
|
2021-10-09 05:51:47 -06:00
|
|
|
connection.Play(-1)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
2021-10-14 10:32:29 -06:00
|
|
|
|
2021-10-17 13:57:30 -06:00
|
|
|
func UpdatePlaylist(conn mpd.Client, t *tview.Table) {
|
|
|
|
_playlistAttr, _ := conn.PlaylistInfo(-1, -1)
|
|
|
|
|
|
|
|
t.Clear()
|
|
|
|
for i, j := range _playlistAttr {
|
|
|
|
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
|
|
|
|
t.SetCell(i, 0, tview.NewTableCell(j["file"]))
|
|
|
|
} else {
|
|
|
|
t.SetCell(i, 0, tview.NewTableCell(j["Title"]))
|
|
|
|
t.SetCell(i, 1, tview.NewTableCell(j["Artist"]))
|
|
|
|
t.SetCell(i, 2, tview.NewTableCell(j["Album"]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-10-17 10:12:02 -06:00
|
|
|
func Update(conn mpd.Client, f []FileNode, inputTable *tview.Table) {
|
|
|
|
inputTable.Clear()
|
|
|
|
for i, j := range f {
|
2021-10-14 10:32:29 -06:00
|
|
|
if len(j.children) == 0 {
|
2021-10-17 10:23:39 -06:00
|
|
|
_songAttributes, err := conn.ListAllInfo(j.absolutePath)
|
2021-10-17 10:12:02 -06:00
|
|
|
if err == nil && _songAttributes[0]["Title"] != "" {
|
2021-10-14 10:32:29 -06:00
|
|
|
inputTable.SetCell(i, 0,
|
2021-10-17 10:12:02 -06:00
|
|
|
tview.NewTableCell("[#fbff00]"+_songAttributes[0]["Title"]).
|
|
|
|
SetAlign(tview.AlignLeft))
|
2021-10-14 10:32:29 -06:00
|
|
|
|
|
|
|
inputTable.SetCell(i, 1,
|
2021-10-17 10:12:02 -06:00
|
|
|
tview.NewTableCell("[#fbff00]"+_songAttributes[0]["Artist"]).
|
|
|
|
SetAlign(tview.AlignLeft))
|
2021-10-14 10:32:29 -06:00
|
|
|
|
|
|
|
inputTable.SetCell(i, 2,
|
2021-10-17 10:12:02 -06:00
|
|
|
tview.NewTableCell("[#ff0030]"+_songAttributes[0]["Album"]).
|
|
|
|
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-17 10:12:02 -06:00
|
|
|
tview.NewTableCell("[#fbff00::b]"+j.path).
|
|
|
|
SetAlign(tview.AlignLeft))
|
2021-10-14 10:32:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|