Fix some absurd capitalization as well as insta-crashing when config files are absent

This commit is contained in:
Sasha Koshka 2024-01-20 20:28:53 +00:00
parent 6e4c3fb452
commit cc6aad66c6
4 changed files with 34 additions and 32 deletions

View File

@ -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)

View File

@ -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")

19
main.go
View File

@ -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)
}

View File

@ -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 {