Added functionality to set image paths

This commit is contained in:
aditya-K2 2021-11-05 14:11:14 +05:30
parent 8e5b675cc4
commit 6a529f4b5e
3 changed files with 9 additions and 3 deletions

View File

@ -16,6 +16,8 @@ var (
"IMAGE_WIDTH_EXTRA_Y": -3.75, "IMAGE_WIDTH_EXTRA_Y": -3.75,
"MUSIC_DIRECTORY": HOME_DIR + "/Music", "MUSIC_DIRECTORY": HOME_DIR + "/Music",
"PORT": "6600", "PORT": "6600",
"DEFAULT_IMAGE_PATH": "default.jpg",
"COVER_IMAGE_PATH": "cover.jpg",
} }
) )

View File

@ -15,7 +15,7 @@ import (
path to default image is sent. path to default image is sent.
*/ */
func getAlbumArt(uri string) string { func getAlbumArt(uri string) string {
var path string = "/H/code/goMP/default.jpg" var path string = viper.GetString("DEFAULT_IMAGE_PATH")
f, err := os.Open(uri) f, err := os.Open(uri)
if err != nil { if err != nil {
panic(err) panic(err)
@ -26,13 +26,13 @@ func getAlbumArt(uri string) string {
} }
albumCover := m.Picture() albumCover := m.Picture()
if albumCover != nil { if albumCover != nil {
b, err := os.Create("/H/code/goMP/thumb.jpg") b, err := os.Create(viper.GetString("COVER_IMAGE_PATH"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer b.Close() defer b.Close()
b.Write(albumCover.Data) b.Write(albumCover.Data)
path = "/H/code/goMP/thumb.jpg" path = viper.GetString("COVER_IMAGE_PATH")
b.Close() b.Close()
} }
f.Close() f.Close()

View File

@ -46,3 +46,7 @@ IMAGE_WIDTH_EXTRA_Y : -3.75
MPD_PORT : "6600" MPD_PORT : "6600"
# Port on which music player daemon is running # Port on which music player daemon is running
DEFAULT_IMAGE_PATH: "default.jpg"
COVER_IMAGE_PATH: "cover.jpg" # path to store the embedded cover art