minor changes in formatting

This commit is contained in:
aditya-K2 2021-12-22 20:41:48 +05:30
parent 0d9227e019
commit 6b7fff82b7
2 changed files with 32 additions and 32 deletions

46
main.go
View File

@ -19,14 +19,14 @@ import (
var ( var (
CONN *mpd.Client CONN *mpd.Client
UI *ui.Application UI *ui.Application
NOTIFICATION_SERVER *NotificationServer Notify *NotificationServer
RENDERER *Renderer RENDERER *Renderer
Volume int64 Volume int64
Random bool Random bool
Repeat bool Repeat bool
InsidePlaylist bool = true InsidePlaylist = true
InsideSearchView bool = false InsideSearchView = false
ARTIST_TREE map[string]map[string]map[string]string ArtistTree map[string]map[string]map[string]string
) )
func main() { func main() {
@ -62,26 +62,26 @@ func main() {
Random, _ = strconv.ParseBool(_v["random"]) Random, _ = strconv.ParseBool(_v["random"])
Repeat, _ = strconv.ParseBool(_v["repeat"]) Repeat, _ = strconv.ParseBool(_v["repeat"])
ARTIST_TREE, err = client.GenerateArtistTree() ArtistTree, err = client.GenerateArtistTree()
ARTIST_TREE_CONTENT := utils.ConvertToArray(ARTIST_TREE) ArtistTreeContent := utils.ConvertToArray(ArtistTree)
NOTIFICATION_SERVER = NewNotificationServer() Notify = NewNotificationServer()
NOTIFICATION_SERVER.Start() Notify.Start()
client.SetNotificationServer(NOTIFICATION_SERVER) client.SetNotificationServer(Notify)
var SEARCH_CONTENT_SLICE []interface{} var SearchContentSlice []interface{}
UI.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) { UI.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
if InsidePlaylist { if InsidePlaylist {
client.UpdatePlaylist(UI.ExpandedView) client.UpdatePlaylist(UI.ExpandedView)
} else if InsideSearchView { } else if InsideSearchView {
client.UpdateSearchView(UI.ExpandedView, SEARCH_CONTENT_SLICE) client.UpdateSearchView(UI.ExpandedView, SearchContentSlice)
} else { } else {
client.Update(dirTree.Children, UI.ExpandedView) client.Update(dirTree.Children, UI.ExpandedView)
} }
return UI.ExpandedView.GetInnerRect() return UI.ExpandedView.GetInnerRect()
}) })
var FUNC_MAP = map[string]func(){ var FuncMap = map[string]func(){
"showChildrenContent": func() { "showChildrenContent": func() {
r, _ := UI.ExpandedView.GetSelection() r, _ := UI.ExpandedView.GetSelection()
if !InsidePlaylist && !InsideSearchView { if !InsidePlaylist && !InsideSearchView {
@ -96,7 +96,7 @@ func main() {
CONN.Play(r) CONN.Play(r)
} else if InsideSearchView { } else if InsideSearchView {
r, _ := UI.ExpandedView.GetSelection() r, _ := UI.ExpandedView.GetSelection()
client.AddToPlaylist(SEARCH_CONTENT_SLICE[r], true) client.AddToPlaylist(SearchContentSlice[r], true)
} }
}, },
"togglePlayBack": func() { "togglePlayBack": func() {
@ -115,7 +115,7 @@ func main() {
}, },
"clearPlaylist": func() { "clearPlaylist": func() {
CONN.Clear() CONN.Clear()
NOTIFICATION_SERVER.Send("PlayList Cleared") Notify.Send("PlayList Cleared")
}, },
"previousSong": func() { "previousSong": func() {
CONN.Previous() CONN.Previous()
@ -126,7 +126,7 @@ func main() {
CONN.Add(dirTree.Children[r].AbsolutePath) CONN.Add(dirTree.Children[r].AbsolutePath)
} else if InsideSearchView { } else if InsideSearchView {
r, _ := UI.ExpandedView.GetSelection() r, _ := UI.ExpandedView.GetSelection()
client.AddToPlaylist(SEARCH_CONTENT_SLICE[r], false) client.AddToPlaylist(SearchContentSlice[r], false)
} }
}, },
"toggleRandom": func() { "toggleRandom": func() {
@ -184,14 +184,14 @@ func main() {
}, },
"stop": func() { "stop": func() {
CONN.Stop() CONN.Stop()
NOTIFICATION_SERVER.Send("Playback Stopped") Notify.Send("Playback Stopped")
}, },
"updateDB": func() { "updateDB": func() {
_, err = CONN.Update("") _, err = CONN.Update("")
if err != nil { if err != nil {
panic(err) panic(err)
} }
NOTIFICATION_SERVER.Send("Database Updated") Notify.Send("Database Updated")
}, },
"deleteSongFromPlaylist": func() { "deleteSongFromPlaylist": func() {
if InsidePlaylist { if InsidePlaylist {
@ -204,12 +204,12 @@ func main() {
}, },
} }
config.GenerateKeyMap(FUNC_MAP) config.GenerateKeyMap(FuncMap)
UI.SearchBar.SetAutocompleteFunc(func(c string) []string { UI.SearchBar.SetAutocompleteFunc(func(c string) []string {
if c != "" && c != " " && c != " " { if c != "" && c != " " && c != " " {
_, _, w, _ := UI.SearchBar.GetRect() _, _, w, _ := UI.SearchBar.GetRect()
matches := fuzzy.Find(c, ARTIST_TREE_CONTENT) matches := fuzzy.Find(c, ArtistTreeContent)
var suggestions []string var suggestions []string
for i, match := range matches { for i, match := range matches {
if i == 10 { if i == 10 {
@ -225,7 +225,7 @@ func main() {
UI.ExpandedView.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey { UI.ExpandedView.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
if val, ok := config.KEY_MAP[int(e.Rune())]; ok { if val, ok := config.KEY_MAP[int(e.Rune())]; ok {
FUNC_MAP[val]() FuncMap[val]()
return nil return nil
} else { } else {
return e return e
@ -237,10 +237,10 @@ func main() {
UI.ExpandedView.Select(0, 0) UI.ExpandedView.Select(0, 0)
InsideSearchView = true InsideSearchView = true
InsidePlaylist = false InsidePlaylist = false
SEARCH_CONTENT_SLICE = nil SearchContentSlice = nil
SEARCH_CONTENT_SLICE, err = client.GenerateContentSlice(UI.SearchBar.GetText()) SearchContentSlice, err = client.GenerateContentSlice(UI.SearchBar.GetText())
if err != nil { if err != nil {
NOTIFICATION_SERVER.Send("Could Not Retrieve the Results") Notify.Send("Could Not Retrieve the Results")
} else { } else {
UI.SearchBar.SetText("") UI.SearchBar.SetText("")
UI.App.SetFocus(UI.ExpandedView) UI.App.SetFocus(UI.ExpandedView)

View File

@ -90,13 +90,13 @@ func getImagePath(path string) string {
if extractedImage == viper.GetString("DEFAULT_IMAGE_PATH") && viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" { if extractedImage == viper.GetString("DEFAULT_IMAGE_PATH") && viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" {
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath) downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath)
if err == nil { if err == nil {
NOTIFICATION_SERVER.Send("Image From LastFM") Notify.Send("Image From LastFM")
extractedImage = downloadedImage extractedImage = downloadedImage
} else { } else {
NOTIFICATION_SERVER.Send("Falling Back to Default Image.") Notify.Send("Falling Back to Default Image.")
} }
} else { } else {
NOTIFICATION_SERVER.Send("Extracted Image Successfully") Notify.Send("Extracted Image Successfully")
} }
} }
} }