2022-08-31 12:12:15 -06:00
|
|
|
package views
|
|
|
|
|
|
|
|
import (
|
2022-09-01 13:55:33 -06:00
|
|
|
"github.com/aditya-K2/gomp/client"
|
|
|
|
"github.com/aditya-K2/gomp/notify"
|
|
|
|
"github.com/aditya-K2/gomp/ui"
|
2022-08-31 12:12:15 -06:00
|
|
|
"github.com/aditya-K2/gomp/utils"
|
|
|
|
"github.com/aditya-K2/tview"
|
2022-09-13 10:34:39 -06:00
|
|
|
"github.com/fhs/gompd/v2/mpd"
|
2022-08-31 12:12:15 -06:00
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PlaylistView struct {
|
2022-09-13 10:34:39 -06:00
|
|
|
Playlist []mpd.Attrs
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s PlaylistView) GetViewName() string {
|
|
|
|
return "PlaylistView"
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetCell(text string, foreground tcell.Color, bold bool) *tview.TableCell {
|
|
|
|
return tview.NewTableCell(text).
|
|
|
|
SetAlign(tview.AlignLeft).
|
|
|
|
SetStyle(tcell.StyleDefault.
|
|
|
|
Foreground(foreground).
|
|
|
|
Background(tcell.ColorBlack).
|
|
|
|
Bold(bold))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p PlaylistView) ShowChildrenContent() {
|
2022-09-01 13:55:33 -06:00
|
|
|
UI := ui.Ui
|
|
|
|
CONN := client.Conn
|
2022-08-31 12:12:15 -06:00
|
|
|
r, _ := UI.ExpandedView.GetSelection()
|
|
|
|
if err := CONN.Play(r); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could Not Play the Song")
|
2022-08-31 12:12:15 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s PlaylistView) ShowParentContent() {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Not Allowed in this View")
|
2022-08-31 12:12:15 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
func (p PlaylistView) AddToPlaylist() {}
|
|
|
|
|
|
|
|
func (p PlaylistView) Quit() {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.App.Stop()
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p PlaylistView) FocusBuffSearchView() {}
|
|
|
|
|
2022-09-14 08:21:06 -06:00
|
|
|
func (p *PlaylistView) DeleteSongFromPlaylist() {
|
2022-09-01 13:55:33 -06:00
|
|
|
UI := ui.Ui
|
|
|
|
CONN := client.Conn
|
2022-08-31 12:12:15 -06:00
|
|
|
r, _ := UI.ExpandedView.GetSelection()
|
|
|
|
if err := CONN.Delete(r, -1); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could not Remove the Song from Playlist")
|
2022-09-14 08:21:06 -06:00
|
|
|
} else {
|
|
|
|
if p.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
|
|
|
|
utils.Print("RED", "Couldn't get the current Playlist.\n")
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
2022-09-14 08:21:06 -06:00
|
|
|
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p PlaylistView) Update(inputTable *tview.Table) {
|
|
|
|
inputTable.Clear()
|
2022-09-14 08:21:06 -06:00
|
|
|
for i, j := range p.Playlist {
|
2022-08-31 12:12:15 -06:00
|
|
|
_, _, w, _ := inputTable.GetInnerRect()
|
|
|
|
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(j["file"], w/3), tcell.ColorBlue, true))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(j["Title"], w/3), tcell.ColorGreen, false))
|
|
|
|
inputTable.SetCell(i, 1,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(j["Artist"], w/3), tcell.ColorPurple, false))
|
|
|
|
inputTable.SetCell(i, 2,
|
|
|
|
GetCell(j["Album"], tcell.ColorYellow, false))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-13 10:34:39 -06:00
|
|
|
|
|
|
|
func (p *PlaylistView) StartWatcher() {
|
|
|
|
var err error
|
|
|
|
if p.Playlist == nil {
|
|
|
|
if p.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
|
|
|
|
utils.Print("RED", "Watcher couldn't get the current Playlist.\n")
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 09:12:28 -06:00
|
|
|
nt, addr := utils.GetNetwork()
|
|
|
|
w, err := mpd.NewWatcher(nt, addr, "", "playlist")
|
2022-09-13 10:34:39 -06:00
|
|
|
if err != nil {
|
|
|
|
utils.Print("RED", "Could Not Start Watcher.\n")
|
|
|
|
utils.Print("GREEN", "Please check your MPD Info in config File.\n")
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for err := range w.Error {
|
|
|
|
notify.Notify.Send(err.Error())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for subsystem := range w.Event {
|
|
|
|
if subsystem == "playlist" {
|
|
|
|
if p.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
|
|
|
|
utils.Print("RED", "Watcher couldn't get the current Playlist.\n")
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|