Fix some absurd capitalization as well as insta-crashing when config files are absent
This commit is contained in:
parent
6e4c3fb452
commit
cc6aad66c6
@ -36,17 +36,17 @@ func TogglePlayBack() error {
|
|||||||
func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) {
|
func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) {
|
||||||
var ContentSlice []interface{}
|
var ContentSlice []interface{}
|
||||||
if strings.TrimRight(selectedSuggestion, " ") == "" {
|
if strings.TrimRight(selectedSuggestion, " ") == "" {
|
||||||
notify.Notify.Send("Empty Search!")
|
notify.Notify.Send("Empty search!")
|
||||||
return nil, errors.New("empty Search String Provided")
|
return nil, errors.New("Empty search string provided")
|
||||||
}
|
}
|
||||||
if _, ok := ArtistTree[selectedSuggestion]; ok {
|
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, selectedSuggestion)
|
||||||
ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Artist Albums :")
|
ContentSlice = append(ContentSlice, WHITE_AND_BOLD+"Artist albums:")
|
||||||
for albumName := range ArtistTree[selectedSuggestion] {
|
for albumName := range ArtistTree[selectedSuggestion] {
|
||||||
ContentSlice = append(ContentSlice, [2]string{albumName, 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 albumName, trackList := range ArtistTree[selectedSuggestion] {
|
||||||
for track := range trackList {
|
for track := range trackList {
|
||||||
ContentSlice = append(ContentSlice, [3]string{track, selectedSuggestion, albumName})
|
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 {
|
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 {
|
for mSlice := range aMap {
|
||||||
ContentSlice = append(ContentSlice, mSlice)
|
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 a, pathSlice := range aMap {
|
||||||
for _, path := range pathSlice {
|
for _, path := range pathSlice {
|
||||||
ContentSlice = append(ContentSlice, [3]string{path[0], a[1], a[0]})
|
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 {
|
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 {
|
for mSlice := range tMap {
|
||||||
ContentSlice = append(ContentSlice, mSlice)
|
ContentSlice = append(ContentSlice, mSlice)
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ func GenerateArtistTree() (map[string]map[string]map[string]string, error) {
|
|||||||
}
|
}
|
||||||
return ArtistTree, nil
|
return ArtistTree, nil
|
||||||
} else {
|
} 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)
|
clist.Add(v)
|
||||||
}
|
}
|
||||||
if err := clist.End(); err != nil {
|
if err := clist.End(); err != nil {
|
||||||
notify.Notify.Send("Could Not Add Album : " + alb)
|
notify.Notify.Send("Could not add album : " + alb)
|
||||||
} else {
|
} 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 {
|
if err := clist.End(); err != nil {
|
||||||
notify.Notify.Send("Could Not Add Artist : " + artist)
|
notify.Notify.Send("Could not add artist: " + artist)
|
||||||
} else {
|
} 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)
|
id, err := Conn.AddID(a[artist][alb][track], -1)
|
||||||
Conn.PlayID(id)
|
Conn.PlayID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
notify.Notify.Send("Could Not Add Track : " + track)
|
notify.Notify.Send("Could not add track: " + track)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := Conn.Add(a[artist][alb][track])
|
err := Conn.Add(a[artist][alb][track])
|
||||||
if err != nil {
|
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)
|
notify.Notify.Send("Track Added : " + track)
|
||||||
|
@ -20,7 +20,7 @@ var (
|
|||||||
"NETWORK_TYPE": "tcp",
|
"NETWORK_TYPE": "tcp",
|
||||||
"NETWORK_ADDRESS": "localhost",
|
"NETWORK_ADDRESS": "localhost",
|
||||||
"MUSIC_DIRECTORY": utils.CheckDirectoryFmt(getMusicDirectory()),
|
"MUSIC_DIRECTORY": utils.CheckDirectoryFmt(getMusicDirectory()),
|
||||||
"PORT": "6600",
|
"MPD_PORT": "6600",
|
||||||
"DEFAULT_IMAGE_PATH": "default.jpg",
|
"DEFAULT_IMAGE_PATH": "default.jpg",
|
||||||
"CACHE_DIR": utils.CheckDirectoryFmt(USER_CACHE_DIR),
|
"CACHE_DIR": utils.CheckDirectoryFmt(USER_CACHE_DIR),
|
||||||
"SEEK_OFFSET": 1,
|
"SEEK_OFFSET": 1,
|
||||||
@ -38,7 +38,7 @@ func ReadConfig() {
|
|||||||
|
|
||||||
err := viper.ReadInConfig()
|
err := viper.ReadInConfig()
|
||||||
if err != nil {
|
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
|
// Expanding ~ to the User's Home Directory
|
||||||
@ -65,8 +65,7 @@ func GenerateKeyMap(funcMap map[string]func()) {
|
|||||||
func getMusicDirectory() string {
|
func getMusicDirectory() string {
|
||||||
content, err := ioutil.ReadFile(HOME_DIR + "/.config/mpd/mpd.conf")
|
content, err := ioutil.ReadFile(HOME_DIR + "/.config/mpd/mpd.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Print("RED", "No Config File for mpd Found.\n")
|
utils.Print("YELLOW", "Could not read MPD config file: " + err.Error() + "\n")
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
ab := string(content)
|
ab := string(content)
|
||||||
maps := strings.Split(ab, "\n")
|
maps := strings.Split(ab, "\n")
|
||||||
|
19
main.go
19
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -24,9 +25,9 @@ func main() {
|
|||||||
var mpdConnectionError error
|
var mpdConnectionError error
|
||||||
client.Conn, mpdConnectionError = mpd.Dial(utils.GetNetwork())
|
client.Conn, mpdConnectionError = mpd.Dial(utils.GetNetwork())
|
||||||
if mpdConnectionError != nil {
|
if mpdConnectionError != nil {
|
||||||
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
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")
|
utils.Print("GREEN", "Make sure you mention the correct MPD port in the config file.\n")
|
||||||
panic(mpdConnectionError)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
Conn := client.Conn
|
Conn := client.Conn
|
||||||
defer Conn.Close()
|
defer Conn.Close()
|
||||||
@ -43,8 +44,8 @@ func main() {
|
|||||||
|
|
||||||
fileMap, err := Conn.ListAllInfo("/")
|
fileMap, err := Conn.ListAllInfo("/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Print("RED", "Could Not Generate the File Map\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")
|
utils.Print("GREEN", "Make sure you mention the correct MPD port in the config file.\n")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,14 +67,14 @@ func main() {
|
|||||||
stime = time.Second * time.Duration(SeekOffset)
|
stime = time.Second * time.Duration(SeekOffset)
|
||||||
}
|
}
|
||||||
if err := Conn.SeekCur(stime, true); err != nil {
|
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 {
|
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)
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
// Setting Volume, Random and Repeat Values
|
// Setting Volume, Random and Repeat Values
|
||||||
@ -84,8 +85,8 @@ func main() {
|
|||||||
|
|
||||||
ArtistTree, err := client.GenerateArtistTree()
|
ArtistTree, err := client.GenerateArtistTree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Print("RED", "Could Not Generate the ArtistTree\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")
|
utils.Print("GREEN", "Make sure you mention the correct MPD port in the config file.\n")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,10 +48,12 @@ func OpenImage(path string, c chan string) {
|
|||||||
var im *ueberzug.Image
|
var im *ueberzug.Image
|
||||||
if path != "stop" {
|
if path != "stop" {
|
||||||
extractedImage := GetImagePath(path)
|
extractedImage := GetImagePath(path)
|
||||||
img2, _ := GetImg(extractedImage)
|
img2, err := GetImg(extractedImage)
|
||||||
im, _ = ueberzug.NewImage(img2,
|
if err == nil {
|
||||||
int(float32(ui.ImgX)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"),
|
im, _ = ueberzug.NewImage(img2,
|
||||||
int(float32(ui.ImgY)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y"))
|
int(float32(ui.ImgX)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"),
|
||||||
|
int(float32(ui.ImgY)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
d := <-c
|
d := <-c
|
||||||
if im != nil {
|
if im != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user