From db9887c041f8d491a157741d0d4e9747d8ab2260 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Mon, 18 Oct 2021 01:27:30 +0530 Subject: [PATCH] Added UpdatePlaylist Function the UpdatePlaylist function updates the table `t` that has been passed to it and fills it with the current playlist. Also I have removed the addsong function which felt unneccesary and unused. --- client.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 24d70b6..dbb6da4 100644 --- a/client.go +++ b/client.go @@ -19,6 +19,21 @@ func togglePlayBack(connection mpd.Client) error { return err } +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"])) + } + } +} + func join(stringSlice []string) string { var _s string = stringSlice[0] for i := 1; i < len(stringSlice); i++ { @@ -59,7 +74,3 @@ func Update(conn mpd.Client, f []FileNode, inputTable *tview.Table) { } } } - -func addSong(conn mpd.Client, currentDirectoryStructure []string, currentCellContent string) { - conn.Add(join(currentDirectoryStructure) + "/" + currentCellContent) -}