From cc6aad66c68d40fc0c82add3876aa33ba3bf895c Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 20 Jan 2024 20:28:53 +0000 Subject: [PATCH] Fix some absurd capitalization as well as insta-crashing when config files are absent --- client/client.go | 30 +++++++++++++++--------------- config/config.go | 7 +++---- main.go | 19 ++++++++++--------- render/render.go | 10 ++++++---- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/client/client.go b/client/client.go index adbdca2..52d77c9 100644 --- a/client/client.go +++ b/client/client.go @@ -36,17 +36,17 @@ func TogglePlayBack() error { func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) { var ContentSlice []interface{} if strings.TrimRight(selectedSuggestion, " ") == "" { - notify.Notify.Send("Empty Search!") - return nil, errors.New("empty Search String Provided") + notify.Notify.Send("Empty search!") + return nil, errors.New("Empty search string provided") } if _, ok := ArtistTree[selectedSuggestion]; ok { - ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Artists :") + ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Artists:") ContentSlice = append(ContentSlice, selectedSuggestion) - ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Artist Albums :") + ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Artist albums:") for albumName := range ArtistTree[selectedSuggestion] { ContentSlice = append(ContentSlice, [2]string{albumName, selectedSuggestion}) } - ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Artist Tracks :") + ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Artist tracks:") for albumName, trackList := range ArtistTree[selectedSuggestion] { for track := range trackList { ContentSlice = append(ContentSlice, [3]string{track, selectedSuggestion, albumName}) @@ -54,11 +54,11 @@ func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) { } } if aMap := QueryArtistTreeForAlbums(ArtistTree, selectedSuggestion); len(aMap) != 0 { - ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Albums :") + ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Albums:") for mSlice := range aMap { ContentSlice = append(ContentSlice, mSlice) } - ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Album Tracks :") + ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Album tracks:") for a, pathSlice := range aMap { for _, path := range pathSlice { ContentSlice = append(ContentSlice, [3]string{path[0], a[1], a[0]}) @@ -66,7 +66,7 @@ func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) { } } if tMap := QueryArtistTreeForTracks(ArtistTree, selectedSuggestion); len(tMap) != 0 { - ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Tracks :") + ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Tracks:") for mSlice := range tMap { ContentSlice = append(ContentSlice, mSlice) } @@ -93,7 +93,7 @@ func GenerateArtistTree() (map[string]map[string]map[string]string, error) { } return ArtistTree, nil } else { - return nil, errors.New("Could Not Generate Artist Tree") + return nil, errors.New("Could not generate artist tree") } } @@ -116,9 +116,9 @@ func AddAlbum(a map[string]map[string]map[string]string, alb string, artist stri clist.Add(v) } if err := clist.End(); err != nil { - notify.Notify.Send("Could Not Add Album : " + alb) + notify.Notify.Send("Could not add album : " + alb) } else { - notify.Notify.Send("Album Added: " + alb) + notify.Notify.Send("Album added: " + alb) } } @@ -132,9 +132,9 @@ func AddArtist(a map[string]map[string]map[string]string, artist string) { } } if err := clist.End(); err != nil { - notify.Notify.Send("Could Not Add Artist : " + artist) + notify.Notify.Send("Could not add artist: " + artist) } else { - notify.Notify.Send("Artist Added: " + artist) + notify.Notify.Send("Artist added: " + artist) } } } @@ -145,12 +145,12 @@ func AddTitle(a map[string]map[string]map[string]string, artist, alb, track stri id, err := Conn.AddID(a[artist][alb][track], -1) Conn.PlayID(id) if err != nil { - notify.Notify.Send("Could Not Add Track : " + track) + notify.Notify.Send("Could not add track: " + track) } } else { err := Conn.Add(a[artist][alb][track]) if err != nil { - notify.Notify.Send("Could Not Add Track : " + track) + notify.Notify.Send("Could not add track: " + track) } } notify.Notify.Send("Track Added : " + track) diff --git a/config/config.go b/config/config.go index 42610ce..17d3d71 100644 --- a/config/config.go +++ b/config/config.go @@ -20,7 +20,7 @@ var ( "NETWORK_TYPE": "tcp", "NETWORK_ADDRESS": "localhost", "MUSIC_DIRECTORY": utils.CheckDirectoryFmt(getMusicDirectory()), - "PORT": "6600", + "MPD_PORT": "6600", "DEFAULT_IMAGE_PATH": "default.jpg", "CACHE_DIR": utils.CheckDirectoryFmt(USER_CACHE_DIR), "SEEK_OFFSET": 1, @@ -38,7 +38,7 @@ func ReadConfig() { err := viper.ReadInConfig() if err != nil { - utils.Print("RED", "Could Not Read Config file.\n") + utils.Print("YELLOW", "Could not read gomp config.\n") } // Expanding ~ to the User's Home Directory @@ -65,8 +65,7 @@ func GenerateKeyMap(funcMap map[string]func()) { func getMusicDirectory() string { content, err := ioutil.ReadFile(HOME_DIR + "/.config/mpd/mpd.conf") if err != nil { - utils.Print("RED", "No Config File for mpd Found.\n") - panic(err) + utils.Print("YELLOW", "Could not read MPD config file: " + err.Error() + "\n") } ab := string(content) maps := strings.Split(ab, "\n") diff --git a/main.go b/main.go index 1008e53..b5405a2 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "os" "strconv" "time" @@ -24,9 +25,9 @@ func main() { var mpdConnectionError error client.Conn, mpdConnectionError = mpd.Dial(utils.GetNetwork()) if mpdConnectionError != nil { - utils.Print("RED", "Could Not Connect to MPD Server\n") - utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n") - panic(mpdConnectionError) + utils.Print("RED", "Could not connect to MPD server: " + mpdConnectionError.Error() + "\n") + utils.Print("GREEN", "Make sure you mention the correct MPD port in the config file.\n") + os.Exit(1) } Conn := client.Conn defer Conn.Close() @@ -43,8 +44,8 @@ func main() { fileMap, err := Conn.ListAllInfo("/") if err != nil { - utils.Print("RED", "Could Not Generate the File Map\n") - utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n") + utils.Print("RED", "Could not generate the file map\n") + utils.Print("GREEN", "Make sure you mention the correct MPD port in the config file.\n") panic(err) } @@ -66,14 +67,14 @@ func main() { stime = time.Second * time.Duration(SeekOffset) } if err := Conn.SeekCur(stime, true); err != nil { - notify.Notify.Send("Could Not Seek Forward in the Song") + notify.Notify.Send("Could not seek forward in the song") } } } } if _v, err := Conn.Status(); err != nil { - utils.Print("RED", "Could Not Get the MPD Status\n") + utils.Print("RED", "Could not get the MPD status\n") panic(err) } else { // Setting Volume, Random and Repeat Values @@ -84,8 +85,8 @@ func main() { ArtistTree, err := client.GenerateArtistTree() if err != nil { - utils.Print("RED", "Could Not Generate the ArtistTree\n") - utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n") + utils.Print("RED", "Could not generate the artist tree\n") + utils.Print("GREEN", "Make sure you mention the correct MPD port in the config file.\n") panic(err) } diff --git a/render/render.go b/render/render.go index daa19ff..207f681 100644 --- a/render/render.go +++ b/render/render.go @@ -48,10 +48,12 @@ func OpenImage(path string, c chan string) { var im *ueberzug.Image if path != "stop" { extractedImage := GetImagePath(path) - img2, _ := GetImg(extractedImage) - im, _ = ueberzug.NewImage(img2, - int(float32(ui.ImgX)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"), - int(float32(ui.ImgY)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y")) + img2, err := GetImg(extractedImage) + if err == nil { + im, _ = ueberzug.NewImage(img2, + int(float32(ui.ImgX)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"), + int(float32(ui.ImgY)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y")) + } } d := <-c if im != nil {