Extracted the process into a new function : getImagePath
This commit is contained in:
parent
b91120252b
commit
e9bcb8ff63
45
render.go
45
render.go
@ -44,24 +44,7 @@ func openImage(path string, c chan string) {
|
|||||||
fw, fh := getFontWidth()
|
fw, fh := getFontWidth()
|
||||||
var im *ueberzug.Image
|
var im *ueberzug.Image
|
||||||
if path != "stop" {
|
if path != "stop" {
|
||||||
a, err := CONN.ListInfo(path)
|
extractedImage := getImagePath(path)
|
||||||
var extractedImage string
|
|
||||||
if err == nil && len(a) != 0 {
|
|
||||||
if val, err := cache.GetFromCache(a[0]["artist"], a[0]["album"]); err == nil {
|
|
||||||
extractedImage = val
|
|
||||||
} else {
|
|
||||||
imagePath := cache.AddToCache(a[0]["artist"], a[0]["album"])
|
|
||||||
absPath := viper.GetString("MUSIC_DIRECTORY") + path
|
|
||||||
extractedImage = extractImageFromFile(absPath, imagePath)
|
|
||||||
if extractedImage == viper.GetString("DEFAULT_IMAGE_PATH") && viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" {
|
|
||||||
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath)
|
|
||||||
if err == nil {
|
|
||||||
NOTIFICATION_SERVER.Send("Image From LastFM")
|
|
||||||
extractedImage = downloadedImage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
img2, _ := getImg(extractedImage)
|
img2, _ := getImg(extractedImage)
|
||||||
im, _ = ueberzug.NewImage(img2, int(float32(IMG_X)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"), int(float32(IMG_Y)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y"))
|
im, _ = ueberzug.NewImage(img2, int(float32(IMG_X)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"), int(float32(IMG_Y)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y"))
|
||||||
}
|
}
|
||||||
@ -83,3 +66,29 @@ func openImage(path string, c chan string) {
|
|||||||
func (self *Renderer) Start(path string) {
|
func (self *Renderer) Start(path string) {
|
||||||
go openImage(path, self.c)
|
go openImage(path, self.c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
This Function returns the path to the image that is to be rendered it checks first for the image in the cache
|
||||||
|
else it adds the image to the cache and then extracts it and renders it.
|
||||||
|
*/
|
||||||
|
func getImagePath(path string) string {
|
||||||
|
a, err := CONN.ListInfo(path)
|
||||||
|
var extractedImage string
|
||||||
|
if err == nil && len(a) != 0 {
|
||||||
|
if val, err := cache.GetFromCache(a[0]["artist"], a[0]["album"]); err == nil {
|
||||||
|
extractedImage = val
|
||||||
|
} else {
|
||||||
|
imagePath := cache.AddToCache(a[0]["artist"], a[0]["album"])
|
||||||
|
absPath := viper.GetString("MUSIC_DIRECTORY") + path
|
||||||
|
extractedImage = extractImageFromFile(absPath, imagePath)
|
||||||
|
if extractedImage == viper.GetString("DEFAULT_IMAGE_PATH") && viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" {
|
||||||
|
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath)
|
||||||
|
if err == nil {
|
||||||
|
NOTIFICATION_SERVER.Send("Image From LastFM")
|
||||||
|
extractedImage = downloadedImage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return extractedImage
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user