diff --git a/globals.go b/globals.go new file mode 100644 index 0000000..4c264ef --- /dev/null +++ b/globals.go @@ -0,0 +1,9 @@ +package main + +var ADDITIONAL_PADDING_X int = 12 +var ADDITIONAL_PADDING_Y int = 16 + +var IMAGE_WIDTH_EXTRA_X float32 = -1.5 +var IMAGE_WIDTH_EXTRA_Y float32 = -3.75 + +var DBDIR string = getMusicDirectory() + "/" diff --git a/imageUtils.go b/imageUtils.go index dac07b0..b2074db 100644 --- a/imageUtils.go +++ b/imageUtils.go @@ -25,13 +25,13 @@ func getAlbumArt(uri string) string { } albumCover := m.Picture() if albumCover != nil { - b, err := os.Create("hello.jpg") + b, err := os.Create("thumb.jpg") if err != nil { panic(err) } defer b.Close() b.Write(albumCover.Data) - path = "hello.jpg" + path = "thumb.jpg" b.Close() } f.Close() @@ -51,8 +51,9 @@ func getImg(uri string) (image.Image, error) { return nil, err } - img = resize.Thumbnail( - uint(IMG_W*22), uint(IMG_H*15), + fw, fh := getFontWidth() + img = resize.Resize( + uint(float32(IMG_W)*(fw+IMAGE_WIDTH_EXTRA_X)), uint(float32(IMG_H)*(fh+IMAGE_WIDTH_EXTRA_Y)), img, resize.Bilinear, ) diff --git a/progressBar.go b/progressBar.go index 17a2e83..3e9ac6e 100644 --- a/progressBar.go +++ b/progressBar.go @@ -10,7 +10,6 @@ import ( ) var CurrentSong string -var DBDIR string = "PATH TO YOUR MPD DATABASE" // The progressBar is just a string which is separated by the color formatting String // for e.g diff --git a/render.go b/render.go index 4da830b..8a85910 100644 --- a/render.go +++ b/render.go @@ -13,9 +13,6 @@ type Renderer struct { c chan string } -var ADDITIONAL_PADDING_X int = 16 -var ADDITIONAL_PADDING_Y int = 24 - /* Returns a new Renderer with a string channel */ diff --git a/utils.go b/utils.go index e89f3a1..6bd3ce1 100644 --- a/utils.go +++ b/utils.go @@ -1,6 +1,9 @@ package main import ( + "fmt" + "io/ioutil" + "os" "strconv" "strings" "syscall" @@ -80,3 +83,27 @@ func formatString(a interface{}) string { return "Paused" } } + +func getMusicDirectory() string { + a, _ := os.UserHomeDir() + content, err := ioutil.ReadFile(a + "/.config/mpd/mpd.conf") + if err != nil { + fmt.Println("No Config File for mpd Found") + panic(err) + } + ab := string(content) + maps := strings.Split(ab, "\n") + for _, j := range maps { + if strings.Contains(j, "music_directory") { + s := strings.SplitAfter(strings.ReplaceAll(j, " ", ""), "y")[1] + d := "" + for z, m := range s { + if (z != 0) && (z != (len(s) - 1)) { + d += string(m) + } + } + return d + } + } + return "" +}