From fb2e2a831ed8c95e246ea9970e0e7e92077f6a35 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Sat, 8 Oct 2022 02:51:22 +0530 Subject: [PATCH] Added Artist, Album fields to FileNode --- client/files.go | 12 +++++++----- main.go | 3 +-- views/fileview.go | 13 +++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/client/files.go b/client/files.go index 77c432c..dde6342 100644 --- a/client/files.go +++ b/client/files.go @@ -13,6 +13,8 @@ type FileNode struct { Parent *FileNode AbsolutePath string Title string + Artist string + Album string } // Source Interface For Fuzzy Searching. @@ -29,11 +31,11 @@ func (f FileNodes) Len() int { return len(f) } -func (f *FileNode) AddChildren(path string, title string) { +func (f *FileNode) AddChildren(path string, title string, artist string, album string) { if f.Path != "" { - f.Children = append(f.Children, FileNode{Children: make([]FileNode, 0), Path: path, Parent: f, AbsolutePath: f.AbsolutePath + "/" + path, Title: title}) + f.Children = append(f.Children, FileNode{Children: make([]FileNode, 0), Path: path, Parent: f, AbsolutePath: f.AbsolutePath + "/" + path, Title: title, Artist: artist, Album: album}) } else { - f.Children = append(f.Children, FileNode{Children: make([]FileNode, 0), Path: path, Parent: f, AbsolutePath: f.AbsolutePath + path, Title: title}) + f.Children = append(f.Children, FileNode{Children: make([]FileNode, 0), Path: path, Parent: f, AbsolutePath: f.AbsolutePath + path}) } } @@ -49,7 +51,7 @@ func GenerateDirectoryTree(path []mpd.Attrs) *FileNode { sepPaths := strings.Split(path[i]["file"], "/") for j := range sepPaths { if len(head.Children) == 0 { - head.AddChildren(sepPaths[j], path[i]["Title"]) + head.AddChildren(sepPaths[j], path[i]["Title"], path[i]["Artist"], path[i]["Album"]) head = &(head.Children[len(head.Children)-1]) } else { var headIsChanged = false @@ -61,7 +63,7 @@ func GenerateDirectoryTree(path []mpd.Attrs) *FileNode { } } if !headIsChanged { - head.AddChildren(sepPaths[j], path[i]["Title"]) + head.AddChildren(sepPaths[j], path[i]["Title"], path[i]["Artist"], path[i]["Album"]) head = &(head.Children[len(head.Children)-1]) } } diff --git a/main.go b/main.go index 1049497..1008e53 100644 --- a/main.go +++ b/main.go @@ -338,9 +338,8 @@ func main() { }) go func() { - drawFunc := func() {} for { - ui.Ui.App.QueueUpdateDraw(drawFunc) + ui.Ui.App.Draw() time.Sleep(time.Second) } }() diff --git a/views/fileview.go b/views/fileview.go index ee0f304..c6a124f 100644 --- a/views/fileview.go +++ b/views/fileview.go @@ -74,20 +74,17 @@ func (f FileView) Update(inputTable *tview.Table) { inputTable.Clear() for i, j := range client.DirTree.Children { if len(j.Children) == 0 { - _songAttributes, err := client.Conn.ListAllInfo(j.AbsolutePath) - if err == nil && _songAttributes[0]["Title"] != "" { + if j.Title != "" { _, _, w, _ := inputTable.GetInnerRect() inputTable.SetCell(i, 0, GetCell( - utils.GetFormattedString(_songAttributes[0]["Title"], w/3), tcell.ColorGreen, false)) - + utils.GetFormattedString(j.Title, w/3), tcell.ColorGreen, false)) inputTable.SetCell(i, 1, GetCell( - utils.GetFormattedString(_songAttributes[0]["Artist"], w/3), tcell.ColorPurple, false)) + utils.GetFormattedString(j.Artist, w/3), tcell.ColorPurple, false)) inputTable.SetCell(i, 2, - GetCell(_songAttributes[0]["Album"], tcell.ColorYellow, false)) - - } else if _songAttributes[0]["Title"] == "" { + GetCell(j.Album, tcell.ColorYellow, false)) + } else if j.Title == "" { inputTable.SetCell(i, 0, GetCell(j.Path, tcell.ColorBlue, true)) }